Pthread__常用

http://blogold.chinaunix.net/u/12909/showart_2183244.html
http://blog.csdn.net/yang_dk/archive/2008/05/23/2471891.aspx
http://www.newsmth.net/pc/pccon.php?id=6592&nid=379676

//  create  a  new  thread,successful return zero
int pthread_create(
pthread_t *restrict thread,           //线程句柄
const pthread_attr_t *restrict attr,  //线程属性:优先级、初始栈大小,是否守护线程。缺省NULL
void *(*start_routine)(void*),        //函数地址
void *restrict arg);                  //函数参数


//  线程显式退出
void pthread_exit(void *value_ptr);

pthread_attr_init (attr)
pthread_attr_destroy (attr)



//  return the thread ID of the calling thread.
pthread_t pthread_self(void);

//  compare the thread IDs t1 and t2.
int pthread_equal(pthread_t t1, pthread_t t2);


//  等待线程终止,获取返回值
int pthread_join(pthread_t thread, void **value_ptr);
//  脱离
int pthread_detach(pthread_t thread);

pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_attr_destroy(&attr);


pthread_attr_setdetachstate (attr,detachstate)
pthread_attr_getdetachstate (attr,detachstate)



pthread_mutex_t mutexsum;

pthread_mutex_init(&mutexsum, NULL);

   pthread_mutex_lock (&mutexsum);
	……
   pthread_mutex_unlock (&mutexsum);

pthread_mutex_destroy(&mutexsum);


//  request that a signal be delivered to the specified thread.
int pthread_kill(pthread_t thread, int sig);

//  request that thread be canceled
int pthread_cancel(pthread_t thread);

/*
  线程创建、等待、结束、返回数据
  线程资源共享
  同步、异步
*/


00疼啊!windows下的 pthread_t竟然是个结构体,
linux下边,却是 typedef unsigned long int pthread_t;
无聊。。。!!!

/*
 * Generic handle type - intended to extend uniqueness beyond
 * that available with a simple pointer. It should scale for either
 * IA-32 or IA-64.
 */
typedef struct {
    void * p;                   /* Pointer to actual object */
    unsigned int x;             /* Extra information - reuse count etc */
} ptw32_handle_t;

你可能感兴趣的:(thread,.net,linux,windows,PHP)