Let's say that I call MailboxProcessor.PostAndReply
, which may run for a very long time due to whatever reasons. What would happen if I call MailboxProcessor.Post
from some other thread while the first call has not returned yet?
What I mean is, yeah, sure, I can write a test that would recreate this situation. However, before I start reinventing the bicycle, I wonder if anyone already knows the answer on this question.
Thanks a lot!
The short answer: no, it doesn't block.
The longer version: Mailbox processor uses a regular Queue<T>
instead of a ConcurrentQueue<T>
- which means posting uses a lock to enqueue, meaning that if a post were to be called from two different threads, one would block the thread till the other call returned - which would happen very fast, but block.
tl;dr: Post does not block is so far as no actual work is done on posting.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.