Andrei
Andrei

Reputation: 8904

boost and single-threaded event-driven model

Boost does not provide single-threaded event-driven model, such that was widespread on Unix before pthreads -- mainloop + "callbacks", does it ?

For example, if I wanted to use boost::message_queue in single-threaded app, and mix it with timers and other asynchronous events (mainloop), then boost does not support it, am I right ?

Upvotes: 6

Views: 4937

Answers (2)

sehe
sehe

Reputation: 393174

I'd look at

  1. Boost::Signals (you can use them precisely as you wish)
  2. Boost::Asio (most importantly: strands). Strands will let you have your cake and eat it too (by having single threaded semantics while still enabling parallel work, on another 'single thread apartment' if you allow my COM-infected pun). This is right on the money with regards to your question because it will automatically synchronize and queue the work to go on the 'main' thread as you call it.

If you are going to combine the two, be sure to use Boost Signals2 (because it supports threading).

Upvotes: 10

Tobu
Tobu

Reputation: 25426

boost::interprocess::message_queue is designed for multiprocessing. In a single-threaded process you can always use an std::queue.

Upvotes: 6

Related Questions