Boost logo

Boost Users :

From: Kesseli Pascal (pascal_kesseli_at_[hidden])
Date: 2008-01-29 19:36:41


Hi everyone

Recently I was trying to synchronize one of my functions using the following
code:

    // write own data to shared vector...
    // ...
    if (++numberOfReadyThreads < numberOfInvolvedThreads) {
        allChargingDataReady.wait(lock);
        return;
    }
    numberOfReadyThreads = 0; // Only the last thread enters this section.
    // write data to file...
    allChargingDataReady.singal_all();

The idea is that all threads submit their data using this function and then
wait before reading in the next set of data until all threads have submitted
their data. The last thread to submit his data is the one who has to write
the collected data to a file.

Using this structure, I find it very simple to realize this behavior.
However, I know from programming with Java that the VM there sometimes
awakens one's threads without any reason, which means that I would have to
realize my condition like this instead:

    // ...
    while(numberOfReadyThreads < numberOfInvolvedThreads) {
        allChargingDataReady.wait(lock);
    }
    // ...

Implementing the same behavior using this snippet is much more complicated
though and I would rather avoid it if possible. And that leads us right away
to my question:

Is the while()-workaround using Boost & C++ needed as well as in Java? Or
can I use the much simpler if()-version?

Thanks for any reply and best regards
Pascal

 

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.19.12/1245 - Release Date: 26.01.2008
15:45
 


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net