1

请参阅 : https ://stackoverflow.com/a/3865121/1071840

我知道如果多个线程将请求推送到单个队列并且缓冲区写入线程将具有读取/更新队列的独占访问权限。那么这个队列可以同时写入和读取,我们将实现无锁序列化。

但我的问题是线程不需要获取队列本身的锁。我希望保持提出请求的顺序。

[这不是作业问题。我只是想了解我们如何通过异步写入来缓解多线程环境中的并发问题]

4

1 回答 1

1

But my question is won't the threads need to acquire lock on the queue itself.

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.

于 2013-01-24T18:27:26.200 回答