Reputation: 19233
I need to make an app that will have two threads. One will produce data (file paths and an action to be performed for that path - create/update/delete) and the other thread will need to consume this data and actually perform the tasks.
For this I thought to have a queue and from one thread to put data in it and from the other to take the items and performa the actions sequentially.
My problem is how do I make this data to be shareable between these threads and then how can I make the second thread to block while waiting for data to be put in the queue? Just having a while to check if queue is not empty would eat CPU like crazy for nothing. Adding a "sleep" to check every few milliseconds or seconds would not be efficient.
How can this be done? Any libraries that implement such data?
Upvotes: 1
Views: 3770
Reputation: 136515
A couple of examples for you:
Upvotes: 5