views:

42

answers:

3

There is a single WCF connection using TCP. Two threads on the server write to this connection consecutively. Is it always guaranteed that the first message gets processed by the client first? According to my understanding it should be guaranteed.

+1  A: 

The 'channel' is sequential, so I think the answer here is Yes.

But with 2 (independent) threads, the meaning of 'first' is not well defined.

Henk Holterman
I think it is well defined. Write operations are atomic, so the "first" thread is... well... the first thread to write. Does not matter which thread it is of the two.
mafutrct
I was referring to the logic of (between) your threads.
Henk Holterman
A: 

I thought about this a bit more, and I believe this question is stupid. Why should WCF care at all which thread writes to a channel?

A write operation to the channel is atomic, and TCP transmission are guaranteed to be in order. Just as Henk pointed out, the channel is totally sequential. It will simply always happen on the client in the exact same order.

mafutrct
A: 

I think Henk's question (what is meant by the 'first' thread) is very interesting.

Given that threads can be suspended at any point, is it possible that Thread A could complete execution of the Send() method before Thread B, but Thread B is the first to return to user code?

From the point of view of the caller, it would look as if Thread B completed the send first.

Matt -The Hat- McVitie