Linux多线程 教程及相关定义

本文详细介绍了POSIX线程中信号量与互斥锁的区别,包括它们的内部类型定义及使用场景。通过比较,帮助开发者更清晰地理解并选择合适的同步原语。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

教程链接:

http://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/

http://www.ibm.com/developerworks/cn/linux/thread/posix_thread2/

http://www.ibm.com/developerworks/cn/linux/thread/posix_thread3/


pthread内部类型定义:
  Type definition file path list:
     /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
     /usr/include/x86_64-linux-gnu/bits/siginfo.h
     /usr/include/x86_64-linux-gnu/bits/semaphore.h
typedef unsigned long in pthread_t;
union pthread_attr_t 
{  
  char __size[56];  
  long int __align;  
};   
union pthread_attr_t 
{     
  char __size[56];
  long int __align;
};
typedef union pthread_attr_t pthread_attr_t; 
typedef union
{  
  struct __pthread_mutex_s  
  {  
    int __lock;  
    unsigned int __count;  
    int __owner;  
  
    unsigned int __nusers;  
  
    int __kind;  
  
    int __spins;  
    __pthread_list_t __list;  
  } __data;  
  char __size[40];  
  long int __align;  
} pthread_mutex_t; 
typedef union  
{  
  struct  
  {   
    int __lock;  
    unsigned int __futex;  
    __extension__ unsigned long long int __total_seq;  
    __extension__ unsigned long long int __wakeup_seq;  
    __extension__ unsigned long long int __woken_seq;  
    void *__mutex;  
    unsigned int __nwaiters;  
    unsigned int __broadcast_seq;  
  } __data;  
  char __size[48];  
  __extension__ long long int __align;  
} pthread_cond_t;  
#if __WORDSIZE == 64
# define __SIZEOF_SEM_T 32
#else
# define __SIZEOF_SEM_T 16
#endif
typedef union
{
  char __size[__SIZEOF_SEM_T];
  long int __align;
} sem_t;

有关信号量和互斥锁的区别 请见

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值