• R
    synchronously clean up pthread_create failure due to scheduling errors · 8a544ee3
    Rich Felker 提交于
    previously, when pthread_create failed due to inability to set
    explicit scheduling according to the requested attributes, the nascent
    thread was detached and made responsible for its own cleanup via the
    standard pthread_exit code path. this left it consuming resources
    potentially well after pthread_create returned, in a way that the
    application could not see or mitigate, and unnecessarily exposed its
    existence to the rest of the implementation via the global thread
    list.
    
    instead, attempt explicit scheduling early and reuse the failure path
    for __clone failure if it fails. the nascent thread's exit futex is
    not needed for unlocking the thread list, since the thread calling
    pthread_create holds the thread list lock the whole time, so it can be
    repurposed to ensure the thread has finished exiting. no pthread_exit
    is needed, and freeing the stack, if needed, can happen just as it
    would if __clone failed.
    8a544ee3
pthread_create.c 10.6 KB