J
Jakob Bieling
Hi,
I have a question regarding optimization of code that uses
synchronization.
template <typename T>
T somefunc ()
{
enter_mutex ();
T t = shared_variable;
leave_mutex ();
return t;
}
Is the compiler allowed to optimize it, so that the code looks sort of
as if it was:
template <typename T>
T somefunc ()
{
enter_mutex ();
leave_mutex ();
return shared_variable;
}
? This is important, since 'shared_variable' must only be accessed after
'enter_mutex' but before 'leave_mutex' is called. Can this be a problem or
do I not have to worry?
thanks!
I have a question regarding optimization of code that uses
synchronization.
template <typename T>
T somefunc ()
{
enter_mutex ();
T t = shared_variable;
leave_mutex ();
return t;
}
Is the compiler allowed to optimize it, so that the code looks sort of
as if it was:
template <typename T>
T somefunc ()
{
enter_mutex ();
leave_mutex ();
return shared_variable;
}
? This is important, since 'shared_variable' must only be accessed after
'enter_mutex' but before 'leave_mutex' is called. Can this be a problem or
do I not have to worry?
thanks!