Please refer to : https://stackoverflow.com/a/3865121/1071840
I understand that if multiple threads will push the requests to a single queue and a buffer write thread will have exclusive access to read/update the queue.. then this queue can be concurrently written to and read from and we’ll achieve lockless serialization.
But my question is won’t the threads need to acquire lock on the queue itself. I wish to maintain the order in which requests were made.
[It’s not a homework question. I’m just trying to understand how do we alleviate concurrency issues in multithreaded environments with asynchronous writes]
Not necessarily. There are concurrent queue implementations (such as this one in .NET, or this implementation in the PPL) which are either entirely lockless, or use much finer grained locking than locking on the entire queue. This can dramatically improve the overall throughput.