Skip to content

std::thread creation spuriously fails #63841

Open
@dvyukov

Description

@dvyukov

While running a program I got a spurious std::system_error exception.
The problem is that std::thread does very simple error handling for pthread_create:

int __ec = _VSTD::__libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get());
if (__ec == 0)

return pthread_create(__t, nullptr, __func, __arg);

But on Linux clone system call can spuriously fail with EAGAIN:
torvalds/linux@498052b

I think std::thread should do what Go runtime does to avoid spuroius exceptions:
https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/runtime/cgo/gcc_libinit.c#L99-L111
Unfortunately it's not a good idea to loop infinitely since EAGAIN can be returned for other reasons (no resources, task limit reached).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving things as opposed to bug fixing, e.g. new or missing featurelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.threadingissues related to threading

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions