[OS] Thread Creation and Termination

The pthread_create() function is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes are used.
  • function定義如下:
#include <pthread.h>

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg);
If successful, the pthread_create() function returns zero. Otherwise, an error number is returned to indicate the error.

pthread_create(thread, attr, start_routine, arg) 四個參數的定義如下:
  • thread: An opaque, unique identifier for the new thread returned by the subroutine.
  • attr: An opaque attribute object that may be used to set thread attributes. You can specify a thread attributes object, or NULL for the default values.
  • start_routine: the C routine that the thread will execute once it is created.
  • arg: A single argument that may be passed to start_routine. It must be passed by reference as a pointer cast of type void. NULL may be used if no argument is to be passed.

Share this post!

Bookmark and Share

0 意見: