Есть ли состояние гонки в реализации GCC std::call_once?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Есть ли состояние гонки в реализации GCC std::call_once?

Сообщение Anonymous »

Основными линиями реализации std::call_once в GCC являются следующие (с _GLIBCXX_HAS_GTHREADS):
'libstdc++-v3/include/std/mutex:939'

Код: Выделить всё

    enum _Bits : int { _Init = 0, _Active = 1, _Done = 2 };
'libstdc++-v3/include/std/mutex:955-967'

Код: Выделить всё

    // RAII helper to call _M_finish.
struct _Active_execution
{
explicit _Active_execution(once_flag& __flag) : _M_flag(__flag) { }

~_Active_execution() { _M_flag._M_finish(_M_returning); }

_Active_execution(const _Active_execution&) = delete;
_Active_execution& operator=(const _Active_execution&) = delete;

once_flag& _M_flag;
bool _M_returning = false;
};
'libstdc++-v3/include/std/mutex:976-1017'

Код: Выделить всё

  inline bool
once_flag::_M_passive() const noexcept
{ return _M_once == _Bits::_Done; }

inline bool
once_flag::_M_activate()
{
if (_M_once == _Bits::_Init) [[__likely__]]
{
_M_once = _Bits::_Active;
return true;
}
else if (_M_passive()) // Caller should have checked this already.
return false;
else
__throw_system_error(EDEADLK);
}

inline void
once_flag::_M_finish(bool __returning) noexcept
{ _M_once = __returning ? _Bits::_Done : _Bits::_Init; }

/// Invoke a callable and synchronize with other calls using the same flag
template
inline void
call_once(once_flag& __once, _Callable&& __f, _Args&&... __args)
{
if (__once._M_passive())
return;
else if (__once._M_activate())                      // 

Подробнее здесь: [url]https://stackoverflow.com/questions/79851546/is-there-a-race-condition-in-gccs-implementation-of-stdcall-once[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»