lundi 23 septembre 2019

Trigger one thread from many others

I'm working on writing my own status bar that comprises many modules (workspaces, clock, open windows, etc) that each run in their own thread. Each of these modules independently waits for an event that they detect (e.g. a minute passing for the clock module) and after which they update their internal value which is meant to be read by the main thread that renders the bar itself. My issue now is how do I let the main thread know that an update has happened and it should wake up and print the new bar? I looked into condition variables but since there are no mutexes to synchronize the main and worker threads together it doesn't seem applicable. If I were doing this in rust I'd use an mpsc channel, have my main thread wait to read from it and have the modules send an empty () message when they're updated to trigger the main thread to reprint the bar. Is there an equivalent like this in c++?

Aucun commentaire:

Enregistrer un commentaire