multithreading - Grabbing a lock that's valid only once in C++ -
I am using C + + 11, where I have 4 threads that are evenly included in a concurrent line Are there. I know when thread processing is done, i.e. the expected final size of the queue.
Now, I want to do a final aggregation work on the content of queue which should be strictly only once . For example, suppose I want to add prices and post it for an external service.
How can I get a lock which is valid only once? I can not use a simple mute because it will not guarantee me once.
Pseudocode:
// If concurrent_queue inside a thread ancu item (concurrent_queue .isize () == EXPECTED_SIZE) {// do something only once} / Code>
A simple solution.
if (concurrent_queue.size () == EXPECTED_SIZE) {// just once, if we bobble, only once = DoItOnceOnly (); }
Comments
Post a Comment