Search code examples
f#mailboxprocessor

order of arrival of message on a mailboxprocessor


Is there /How can I get guarantee on the order of arrival for the messages sent to a mailboxprocessor

That is, on a thread if I do

agent.post(msg1)
agent.post(msg2)

How can I be sure that, in the treatment loop for the agent, the messages will be received in order ?


Solution

  • They are. The implementation of Post is as you might guess, it just adds an item to the queue (on the current thread, under a lock), and posts work to notify any waiting agent to wake up and process it. So if you call Post twice on the same thread, one after another, the messages get into the queue in that order.