
四个线程运行时的内存大致情况

#include <pthread.h>
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start)(void*), void *arg);
// 成功时返回 0,失败则返回错误号
arg 的函数 start (即 start(arg)) 而开始执行。pthread_t 类型的缓冲区,在**pthread_create()**返回前,会在此保存一个该线程的唯一标识。后续的 Pthreads 函数将使用该标识来引用此线程。
attr 是指向 pthread_attr_t 对象的指针,该对象指定了新线程的各种属性。线程的终止有四个选择:
pthread_exit()。pthread_cancel()取消线程。