What's the basic structure of a event loop system in C++11? How are the key elements (such as message queue, message dispatcher, signal) implemented? For example, do I still need a std::queue<Message>
, a std::mutex
and a std::condition_variable
as what I did in c++98 + boost way? Also, the performance matters in the solution I'm seeking for.
Asked
Active
Viewed 1,623 times
6

Paul Sweatte
- 24,148
- 7
- 127
- 265

GuLearn
- 1,814
- 2
- 18
- 32
-
5There are no high level classes such as message queues in the standard, so you would still have to make your own out of the types you mention. – juanchopanza May 16 '13 at 19:56
-
5If performance matters, stick with mechanisms native to the target OS. For example, use `kqueue` if targeting OS X, or `epoll` for best results on Linux. C++11 has nothing to do with this. – May 16 '13 at 21:30
-
2If you're using Boost already, you could use Boost.Asio. – beerboy May 17 '13 at 03:15
1 Answers
2
Do it roughly the same way you would have done it in C++98. You can replace some platform-specific things like pthread_t, pthread_mutex, and pthread_cond with standardized equivalents (std::thread, std::{recursive_,}{timed_,}mutex, and std::condition_variable{,_any}), but the basic design is the same.
As @beerboy mentioned, Boost.Asio might be a good place to start even though AFAIK it hasn't been updated for C++11 yet.

Jeffrey Yasskin
- 5,171
- 2
- 27
- 39