Dears,
I had observed dead lock in call_once (posix code). How to understand what causes this dead lock?
Windows code works well - my usage of call_once runs normally on windows, but ported to Linux
hangs.
Below I had marked where the code is waiting (endless) - see line with '// ***'.
I understand that condition "flag.epoch==uninitialized_flag" is not fullfilled, but
"flag.epoch==being_initialized" is passed. So it seems that: pthread_cond_wait
is waiting, but I have no clue for what it is waiting. Especially that I have
no real access to "detail::once_epoch_cv" - seems to be private member of the
namespace. Also I observed that there is single hit to that function. The while
loop is done once - program is entering while and stops on the first pthread_cond_wait.
template<typename Function>
void call_once(once_flag& flag,Function f)
if(flag.epoch==uninitialized_flag)
{
flag.epoch=being_initialized;
try
{
pthread::pthread_mutex_scoped_unlock relocker(&detail::once_epoch_mutex);
f();
}
catch(...)
{
flag.epoch=uninitialized_flag;
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
throw;
}
flag.epoch=--detail::once_global_epoch;
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
}
else
{
while(flag.epoch==being_initialized)
{
BOOST_VERIFY(!pthread_cond_wait(&detail::once_epoch_cv,&detail::once_epoch_mutex)); // *** first hit here causes dead lock
}
}
Best regards,
Seweryn Habdank-Wojewodzki.