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?
, . pthread_exit pthread_cancel, - pthread_join, pthread, .
pthread_join (tid, NULL) .
( waitpid, pthread_join)
EAGAIN . , , pthread_attr_setstacksize(). , . getrlimit(), RLIMIT_NPROC .
pthread_attr_setstacksize()
getrlimit()
, , , , .. , - - , , , ( ) - .
pthread_create(). , , , , , , , EAGAIN .
pthread_create()
, 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); }
: (EAGAIN on pthread_create), pthread_attr_init pthread_attr_t, .
EAGAIN
pthread_create
pthread_attr_init
pthread_attr_t
" - "? , ...
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; }
Source: https://habr.com/ru/post/1688606/More articles:CSS3 grid markup: a new line after a specific element - maybe? - cssSort an array by multiple fields (closest to a number) - sortingHow to check which date is the latest? - dateLadda Button will not work in Safari - jquerypthread_create does not work with EAGAIN - cSecurityContext with authentication / default user - javareaddir returns dirent with d_type == DT_UNKNOWN for directories. and also - cCodepen dashboard doesn't display content in iframe - htmlКак запустить интеграционные тесты JUnit 5 с плагином Maven Failsafe? - javaDexArchiveMergerException with Android Studio 3.0 - androidAll Articles