我以為pthread_win32 完全兼容posix 的pthread呢,結果發現,至少有一個地方不同,pthread_t的類型。
posix下pthread_t的類型是:
typedef unsigned long int pthread_t; //come from /usr/include/bits/pthread.h //用途:pthread_t用於聲明線程ID。 //sizeof (pthread_t) =4;
而pthread_win32 是:
/* * 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; typedef ptw32_handle_t pthread_t;
這樣就存在一點不兼容的問題了。
void * p 可以看做是posix的pthread_t 的 類型,但是多了一個 x,額外的信息,重用計數器。其大小就是4個字節了。
不知道還有沒有其他的不同之處。至少暫時 還是非常好的。
