Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C , how to create thread using pthread_create function

Tags:

People also ask

How do I create a thread with Pthread?

In main(), we declare a variable called thread_id, which is of type pthread_t, which is an integer used to identify the thread in the system. After declaring thread_id, we call pthread_create() function to create a thread. pthread_create() takes 4 arguments.

How many threads does pthread_create create?

pthread_create() inspects this address space before creating a new thread. A realistic limit is 200 to 400 threads.

Does pthread_create create a kernel thread?

pthread_create simply creates a thread. Not "a kernel-level thread" or "a user-level thread".

Which type of thread is created by the pthread_create API?

the following two thread creation mechanisms are functionally equivalent: rc = pthread_create(&t, NULL, foo, NULL); rc = pthread_create(&t, &attr, foo, NULL); The cancellation state of the new thread is PTHREAD_CANCEL_ENABLE. The cancellation type of the new thread is PTHREAD_CANCEL_DEFERRED.


I'm making a c file for a dispatch queue that gets a task and put it in to a queue which is the linked list. In order to do this, I need to create threads using

pthread_t cThread; if(pthread_create(&cThread, NULL, work, param)){     perror("ERROR creating thread."); } 

However I need to make another function that goes into 'work' and 'param' variable as parameters of create function. My friend told me that I just need to put any code in the work function that loops infinitely so the thread does not die.. Can anyone explain each parameter goes in to the pthread_create function- especially for work and param? I searched Google for this, but most of tutorials are so hard to understand the concept...


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!