Boost logo

Boost :

From: Michael Glassford (glassfordm_at_[hidden])
Date: 2005-03-29 16:57:51


Janusz Piwowarski wrote:
> Hi all,
>
> When Boost.Thread is compiled in release mode, there are a lot of
> warnings about unused variable 'int loop_count' in read_write_mutex.cpp.
> They comes from code like:
>
> int loop_count = 0;
> while (m_state == -1)
> {
> BOOST_ASSERT(++loop_count == 1);
> ++m_num_waiting_readers;
> m_waiting_readers.wait(l);
> --m_num_waiting_readers;
> }
>
> If loop is for second evaluation of condition only, i think it would be
> better to write:
>
> if (m_state == -1)
> {
> ++m_num_waiting_readers;
> m_waiting_readers.wait(l);
> --m_num_waiting_readers;
> BOOST_ASSERT(m_state != -1);
> }
>

The warnings are now fixed, though not in the manner suggested. The loop
is necessary, and there are times when it is correct to loop more than
once. The loop count is debugging code to find times when the loop was
executing more than once incorrectly. It is now completely removed from
release builds.

Mike


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk