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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -