[Bug c++/54729] New: __compare_and_swap does not return on all paths
cvoica at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Sep 27 16:40:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54729
Bug #: 54729
Summary: __compare_and_swap does not return on all paths
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: cvoica@gmail.com
I had wrongly used the __compare_and_swap with a "volatile bool" variable and
without the _GLIBCXX_DEBUG and _GLIBCXX_PARALLEL being defined.
Analyzing the function I would like to suggest to return false before leaving
the function, otherwise the user belive that the CAS was successful while he is
actually using it incorrectly.
Possible solution is something like this.
template<typename _Tp>
inline bool
__compare_and_swap(volatile _Tp* __ptr, _Tp __comparand, _Tp __replacement)
{
if (sizeof(_Tp) == sizeof(int32_t))
return __compare_and_swap_32((volatile int32_t*) __ptr,
(int32_t)__comparand,
(int32_t)__replacement);
else if (sizeof(_Tp) == sizeof(int64_t))
return __compare_and_swap_64((volatile int64_t*) __ptr,
(int64_t)__comparand,
(int64_t)__replacement);
else
_GLIBCXX_PARALLEL_ASSERT(false);
return false;
}
More information about the Gcc-bugs
mailing list