Thread Creation: pthread_create

Function Prototype

int pthread_create(
	pthread_t *tidp,
	pthread_attr_t *attr,
	void *(*start_rtn)(void *),
	void *arg
);
  • tidp:存 thread id
  • attr:設定 thread attribute (NULL: default)
  • start_rtn:thread 建立後執行的函數
  • arg:指向 start_rtn 參數的 pointer

start_rtn 的參數只能是指標

Function

建立一個新的 thread

我們並不保證當新的 thread 建立後是原本的 thread 還是新的 thread 會先執行