Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost and single-threaded event-driven model

Tags:

c++

events

boost

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 ?

like image 358
Andrei Avatar asked Jun 11 '11 19:06

Andrei


People also ask

Is event-driven programming single threaded?

js is a single-threaded but highly scalable system that utilizes JavaScript as its scripting language. It uses asynchronous, event-driven I/O instead of separate processes or threads.

What is event-driven and non blocking?

Event-driven architecture makes the server highly scalable and it does not wait for an API to return data, it moves to the next API immediately for the next request. Non-blocking operation means the server will not block itself for one request.

What is Eventloop based server?

JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks. This model is quite different from models in other languages like C and Java.


Video Answer


2 Answers

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).

like image 128
sehe Avatar answered Oct 05 '22 21:10

sehe


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

like image 20
Tobu Avatar answered Oct 05 '22 22:10

Tobu