Pthread_create and EAGAIN

I got EAGAIN when trying to create a thread using pthread_create. However, from what I checked, the threads seemed to be terminated correctly.

What determines the OS to provide EAGAIN when trying to create a thread using pthread_create? Is it possible that unclosed sockets / file descriptors play a role in calling this EAGAIN (i.e. they use the same resource space)?

And finally, is there any tool to check resource usage, or any functions that can be used to see how many active pthread objects are currently in use?

+3
source share
5 answers

, . pthread_exit pthread_cancel, - pthread_join, pthread, .

pthread_join (tid, NULL) .

( waitpid, pthread_join)

+7

EAGAIN . , , pthread_attr_setstacksize(). , . getrlimit(), RLIMIT_NPROC .

, , , , .. , - - , , , ( ) - .

pthread_create(). , , , , , , , EAGAIN .

+3

, pthread_join(), , pthread_exit() pthread_cancel(), . , pthread_detach() pthread_create(), . -

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);
}
+1

: (EAGAIN on pthread_create), pthread_attr_init pthread_attr_t, .

0

" - "? , ...

void printRlimit(const char *msg, int resource){
   struct rlimit rlim;
   getrlimit(resource, &rlim);
   printf("\n%s ", msg);
   printf("soft=");

   if (rlim.rlim_cur == RLIM_INFINITY)
       printf("infinite");
   else if (rlim.rlim_cur == RLIM_SAVED_CUR)
       printf("unrepresentable");
   else
       printf("%lld", (long long) rlim.rlim_cur);

   printf(" hard=");
   if (rlim.rlim_max == RLIM_INFINITY)
     printf("infinite\n");
   else if (rlim.rlim_max == RLIM_SAVED_MAX)
       printf("unrepresentable");
   else
       printf("%lld\n", (long long) rlim.rlim_max);
}

int main(){
   printRlimit("RLIMIT_AS", RLIMIT_STACK);
   printRlimit("RLIMIT_CORE", RLIMIT_CORE);
   printRlimit("RLIMIT_CPU", RLIMIT_CPU);
   printRlimit("RLIMIT_DATA", RLIMIT_DATA);
   printRlimit("RLIMIT_FSIZE", RLIMIT_FSIZE);
   printRlimit("RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
   printRlimit("RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE);
   printRlimit("RLIMIT_NPROC", RLIMIT_NPROC);
   printRlimit("RLIMIT_NICE", RLIMIT_NICE);
   printRlimit("RLIMIT_NOFILE", RLIMIT_NOFILE);
   printRlimit("RLIMIT_RSS", RLIMIT_RSS);
   printRlimit("RLIMIT_RTPRIO", RLIMIT_RTPRIO);
   printRlimit("RLIMIT_RTTIME", RLIMIT_RTTIME);
   printRlimit("RLIMIT_SIGPENDING", RLIMIT_SIGPENDING);
   printRlimit("RLIMIT_STACK", RLIMIT_STACK);
   return 0;
}
0

Source: https://habr.com/ru/post/1688606/


All Articles