Pthread_create() returns the error code to specify the result of thread creation request. Int err = pthread_create(&threadId, NULL, &threadFunc, NULL) Create a thread that will function threadFunc() So, now let’s call pthread_create() by passing function pointer and other arguments i.e. This function should accept a void * and return void * too. Function pointer to the function that thread will run in parallel on start.Attributes to set the properties of thread.Pointer of the Thread ID, it will update the value in it.Pthread_create() accepts 4 arguments i.e. Void *(*start_routine) (void *), void *arg) Int pthread_create(pthread_t *thread, const pthread_attr_t *attr, Now suppose we have a function that we want to run in parallel to main function i.e. Each thread will have its own,Įach of thread shares the process address space and can access heap, global and static variables. POSIX Thread library provides various functions to create and control threads. In this article we will discuss how to create a thread in C or C++ using POSIX Thread Library on Linux.Ĭreating a thread will create a separate execution unit with in the same process.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |