chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.7k stars 5.15k forks source link

how to ensure the thread safe access to circular_beffer? #542

Closed justnull closed 2 years ago

justnull commented 2 years ago

https://github.com/chenshuo/muduo/blob/90920bbad80e544da9a8a94b16ad8ab4bb66e652/examples/idleconnection/echo.h#L9 https://www.boost.org/doc/libs/1_54_0/libs/circular_buffer/doc/circular_buffer.html#threadsafety If multiple threads access a single circular_buffer, and at least one of the threads may potentially write, then the user is responsible for ensuring mutual exclusion between the threads during the container accesses. The mutual exclusion between the threads can be achieved by wrapping operations of the underlying circular_buffer with a lock acquisition and release.

does ::onCnnection and ::onMessage always run in a single thread?

chenshuo commented 2 years ago

muduo/examples/idleconnection is a single thread program.