pthread_t definition
近期在看google的chromium的代码,认为其基础库base中的对于与平台有关的线程的数据结构的定义与其代码中的凝视部分不匹配。
// PlatformThreadHandle should not be assumed to be a numeric type, since the
// standard intends to allow pthread_t to be a structure. This means you
// should not initialize it to a value, like 0. If it's a member variable, the
// constructor can safely "value initialize" using () in the initializer list.
#if defined(OS_WIN)
#include <windows.h>
typedef DWORD PlatformThreadId;
typedef void* PlatformThreadHandle; // HANDLE
const PlatformThreadHandle kNullThreadHandle = NULL;
#elif defined(OS_POSIX)
#include <pthread.h>
typedef pthread_t PlatformThreadHandle;
const PlatformThreadHandle kNullThreadHandle = 0;
#if defined(OS_MACOSX)
#include <mach/mach.h>
typedef mach_port_t PlatformThreadId;
#else // OS_POSIX && !OS_MACOSX
#include <unistd.h>
typedef pid_t PlatformThreadId;
#endif
#endif
凝视明白说明 phtread_t在标准中有被定义为一个结构体的可能性,但其在实际代码中仍然出现了:
#include <pthread.h>
typedef pthread_t PlatformThreadHandle;
const PlatformThreadHandle kNullThreadHandle = 0;
显然此写法肯定不是个错误,否则chromium在posix系统上就编译只是去了。
为此专门search了一下pthread_t的定义,发现非常真是有多种定义方法,
在linux的实现中pthread_t被定义为 "unsigned long int", 參见例如以下具体说明:
With LinuxThreads (the default Pthreads library on 2.4 kernel), the
pthread_t was in fact related to an index of an internal table. With
NPTL, the pthread_t holds the memory address of a structure that
describes the thread properties.
在Windows中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;
typedef ptw32_handle_t pthread_t;
从而导致例如以下代码不具有可移植性:
pthread_t tid;
.....
tid = (pthread_t)0;
正确的实现应该是用memset()来将其初始化为0,虽然在有的系统的实现中,将pthread_t的变量初始化为0也未必是一个正确的选择。
pthread_t definition的更多相关文章
- foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because 'System.Web.UI.WebControls.Table' does not contain a public definition for 'GetEnumerator'
错误:foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because ' ...
- `UnityEditor.EditorUtility' does not contain a definition for `GetMiniThumbnail'
I got the following errors with Untiy 4.0f7error CS0117: `UnityEditor.EditorUtility' does not contai ...
- 原创: How to build a query based on Definition Updates installed
In SCCM 2012 R2, you can use following class. Use SMS_CombinedDeviceResources.EPAntivirusSignatureLa ...
- Definition of success-成功的定义
"My definition of success is doing what you love. I fell many people do things because they fee ...
- XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
XML Schema 语言也称作 XML Schema 定义(XML Schema Definition,XSD),作用是定义 XML 文档的合法构建模块,类似 DTD,但更加强大. 作用有: ①定义 ...
- TFS Build Definition And Auto Deploy
一台build machine上一般只有一个build service[对应一个build controller]来serve一个team project collection,但又workaroun ...
- multiple definition of `err_sys' 《UNIX环境高级编程》
本文地址:http://www.cnblogs.com/yhLinux/p/4079930.html 问题描述: [点击此处直接看解决方案] 在练习<UNIX环境高级编程>APUE程序清单 ...
- Mysql运行SQL文件 错误Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
问题描述 想从服务器上DOWN下数据库.操作:先把数据库转存为SQL文件,然后在本地利用navicate运行SQL文件,出现错误信息: Incorrect table definition;there ...
- Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification version
Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification ...
随机推荐
- (转)mysql分表的3种方法
原文:http://blog.51yip.com/mysql/949.html 一,先说一下为什么要分表 当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿 ...
- Find the maximum(规律,大数)
Find the maximum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- linux学习方法之二
相信不少想学习linux的新手们正愁不知道看什么linux学习教程好,下面小编给大家收集和整理了几点比较重要的教程,供大家学习,如需想学习更多的话,可到wdlinux学堂寻找更多教程. 安装php扩展 ...
- Linux各个目录的作用
/binbin是binary的缩写.这个目录沿袭了UNIX系统的结构,存放着使用者最经常使用的命令.例如cp.ls.cat,等等./boot这里存放的是启动Linux时使用的一些核心文件./dev ...
- "a newer version of unity web player is required but the auto-update failed"
问题背景描述: 项目采用winform调用unity web player作为播放器在客户端使用. 在有些环境会出现标题所示错误. 经过一翻研究后发现是插件在向服务器请求更新以下文件时报http 30 ...
- HTML基础知识笔记(一)
HTML定义 HTML指的是超文本标记语言 HTML不是编程语言,而是标记语言 标记语言是一套标记标签 HTML是用标记标签来描述网页 HTML标签1 <html></html& ...
- HTML 表单与输出
我们先来设置一个简单的表单 <!doctype html><html><head> <meta charset="utf-8"> & ...
- PHP学习笔记二十六【类的重载】
<?php //重载: //函数名一样,通过函数的参数个数或者是参数类型不同,达到调用同一个函数名 Class A{ // public function test1(){ // echo &q ...
- asp.net缓存(一)
ASP.NET页面输出缓存(OutputCache) 页面输出缓存是最为简单的缓存机制,该机制将整个ASP.NET页面内容保存在服务器内存中.当用户请求该页面时,系统从内存中输出相关数据,直到缓存数据 ...
- 监听SWT文本框只能输入数字
在SWT开发中,很多时候需要文本框只能输入数字(当输入字母或者其他字符时为无效),这个时候需要给文本框设置监听VerifyListener, code 如下: text.addVerifyListen ...