Boost logo

Boost Users :

Subject: Re: [Boost-users] Tracking down a race condition
From: Roland Bock (rbock_at_[hidden])
Date: 2010-01-26 02:48:26


Stephen Torri wrote:
> On Mon, 2010-01-25 at 19:38 +0100, Roland Bock wrote:
>
>> You can see what is happening by making the writing of logs slower:
>>
>> void Trace::threadMain()
>> {
>> boost::this_thread::sleep(boost::posix_time::seconds(1)); //
>> Insert this
>> boost::unique_lock<boost::mutex> lock ( m_lock );
>> ...
>
> I made it slower adding in the line. I did not see anything in the
> output. How did you observe the program after adding that line? Did you
> use a debugger or just execute it?

Hi,

if I read your original code correctly, you have two threads: one closes
the file, one wants to write to it. If you have a racing condition, you
can often see a change by making one thread slower. And voila, there is
a change: Instead of something getting an empty log file, you now always
get an empty log file (the close always wins the race).

No debugger needed for this.

Regarding your new problem: Please try to isolate the problem in code
that compiles and consists of a few dozen lines (the less, the more
probable that someone will take the time to read it).

Regards,

Roland


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