This is my next challenge.
I have several threads waiting there. Another thread is polling a database and when it finds something, it puts something in a datastructure that is owned by a thread (every thread owns one of those structures). Currently all those threads do a constant loop with a usleep of 200 ms. Without a sleep this would take too much CPU power. This isn't fast enough for me though, I want that the threads are each locked and awaken as soon as the polling threads has no data for them.
I did this with a condition variable and it kinda works but I think it's wrong. I just have every thread blocking at a condition variable, then when the polling thread has new data it sends a pthred_cond_broadcast to awaken all threads. This works but I don't think it's "good". When I understand condition variables correctly, that's not how they are supposed to be used.
What I want to do is, that the polling thread can signal certain threads to awake (yes I will store the ID's of each thread of course). So whenever it has finished putting the data into a threads buffer it should signal it something like "check your buffer". The thread then reads this buffer, works with it and blocks again waiting for the next call.
Any ideas how this could be done?