pthread_create and EAGAIN

前端 未结 5 873
独厮守ぢ
独厮守ぢ 2021-01-18 18:13

I got an EAGAIN when trying to spawn a thread using pthread_create. However, from what I\'ve checked, the threads seem to have been terminated properly.

What determi

5条回答
  •  一向
    一向 (楼主)
    2021-01-18 18:31

    As per my observation if one of the parent process calls pthread_join(), and chilled processes are trying to release the thread by calling pthread_exit() or pthread_cancel() then system is not able to release that thread properly. In that case, if pthread_detach() is call immediately after successful call of pthread_create() then this problem has been solved. A snapshot is here -

    err = pthread_create(&(receiveThread), NULL, &receiver, temp);
    if (err != 0)
    {
     MyPrintf("\nCan't create thread Reason : %s\n ",(err==EAGAIN)?"EAGAUIN":(err==EINVAL)?"EINVAL":(err==EPERM)?"EPERM":"UNKNOWN");
        free(temp);
    }
    else
    {
        threadnumber++;
        MyPrintf("Count: %d Thread ID: %u\n",threadnumber,receiveThread);
        pthread_detach(receiveThread);
    }
    

提交回复
热议问题