简体   繁体   中英

interaction between Queue and pool of Threads?

I am creating a C++ application that receives data from an external provider. The amount of data per second can be very big. I have thought of using a thread that pushes the data into a Queue. then a pool of threads will fetch data from that Queue.

my questions are:

  1. is this a good way to deal with this problem?

  2. if not what is the best solution?

Thanks.

1- is this a good way to deal with this problem.

It's a well known pattern, and used in many applications.

You can use a std:queue to implement this. Just protect the read/write operations on it using a std:mutex . Also you should have a condition variable or semaphore, where the pooled threads are waiting, and be notified, when new data is available in the queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM