KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: The thread create by pthread_create the same with the kernel thread? I use the code below to test the maximum number of threads that the pthread_create function can create. #include <pthread.h> #include <stdio.h> static unsigned long long thread_nr = 0; pthread_mutex_t mutex_; void* inc_thread_nr(void* arg) { (void*)arg; pthread_mutex_lock(&mutex_); thread_nr ++; pthread_mutex_unlock(&mutex_); /* printf("thread_nr = %d\n", thread_nr); */ sleep(300000); } int main(int argc, char *argv[]) { int err; int cnt = 0; pthread_t pid[1000000]; pthread_mutex_init(&mutex_, NULL); while (cnt < 1000000) { err = pthread_create(&pid[cnt], NULL, (void*)inc_thread_nr, NULL); if (err != 0) { break; } cnt++; } pthread_join(pid[cnt], NULL); pthread_mutex_destroy(&mutex_); printf("Maximum number of threads per process is = %d\n", thread_nr); } And the output is : Maximum number of threads per process is = 825 Is that the maximum number of threads that the pthread_create function can create? Besides, I use the command below to view the maximum number of threads my system allows: # cat /proc/sys/kernel/threads-max And the number is 772432. Why is the output of my program not equal to the value of threads-max ? My OS is Fodaro 16, with 12 cores, 48G RAM.
Tags (comma-separated)
Save Edits
Cancel