pthread_win32下的 pthread_t與posix的pthread_t的不同。


我以為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個字節了。

不知道還有沒有其他的不同之處。至少暫時 還是非常好的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM