惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
V
V2EX
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
S
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
美团技术团队
S
Security Affairs
AI
AI
SecWiki News
SecWiki News
Hugging Face - Blog
Hugging Face - Blog
B
Blog
小众软件
小众软件
Cloudbric
Cloudbric
V
Visual Studio Blog
PCI Perspectives
PCI Perspectives
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Schneier on Security
Schneier on Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
N
News and Events Feed by Topic
博客园 - 叶小钗
Last Week in AI
Last Week in AI
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Google Online Security Blog
Google Online Security Blog
TaoSecurity Blog
TaoSecurity Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
SegmentFault 最新的问题
F
Full Disclosure
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
博客园 - 三生石上(FineUI控件)
T
The Blog of Author Tim Ferriss
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
博客园 - Franky

博客园 - y轴

Apache服务器配置技巧(转) 网站架构收集 (转) 谈谈网站静态化(转) 经典SQL语句集锦(转) Linux中find常见用法示例(转) linux 进程间通信(转) stl(转) stl总结(转) 网络编程指南(转) Linux 套接字编程中的 5 个隐患(转) linux socket 常用函数 MySQL与事务(转) 在PHP中实现进程间通讯 (转) mysql storge engine(转) apache Order Deny 的配置 apache rewrite原理与使用(转) 利用apache代理功能实现负载均衡的集群(转) HTTP Referer二三事 (转) 非捕获,前瞻与后顾(转)
pthread 常用函数
y轴 · 2008-08-28 · via 博客园 - y轴

nt pthread_create(
               pthread_t *tid,
               const pthread_attr_t *attr,
               void*(*start_routine)(void*),
               void *arg
               );
//参数tid 用于返回新创建线程的线程号;
//start_routine 是线程函数指针,线程从这个函数开始独立地运行;
//arg 是传递给线程函数的参数。由于start_routine 是一个指向参数类型为void*,返回值为void*的指针,所以如果需要传递或返回多个参数时,可以使用强制类型转化。

void pthread_exit(
             void* value_ptr
             );
// 参数value_ptr 是一个指向返回状态值的指针。

int pthread_join(
             pthread_t tid ,
             void **status
             );
// 参数tid 是希望等待的线程的线程号,status 是指向线程返回值的指针,线程的返回值就是pthread_exit 中的value_ptr 参数,或者是return语句中的返回值。该函数可用于线程间的同步。

int pthread_mutex_init(
                   pthread_mutex_t *mutex,
                   const pthread_mutex_attr_t* attr
                   );
//该函数初始化一个互斥体变量,如果参数attr 为NULL,则互斥
//体变量mutex 使用默认的属性。

int pthread_mutex_lock(
                   pthread_mutex_t *mutex
                   );
// 该函数用来锁住互斥体变量。如果参数mutex 所指的互斥体已经
//被锁住了,那么发出调用的线程将被阻塞直到其他线程对mutex 解锁。

int pthread_mutex_trylock(
                      pthread_t *mutex
                      );
//该函数用来锁住mutex 所指定的互斥体,但不阻塞。如果该互斥
//体已经被上锁,该调用不会阻塞等待,而会返回一个错误代码。

int pthread_mutex_unlock(
                     pthread_mutex_t *mutex
                     );
//该函数用来对一个互斥体解锁。如果当前线程拥有参数mutex 所
//指定的互斥体,该调用将该互斥体解锁。

int pthread_mutex_destroy (
                       pthread_mutex_t *mutex
                       );
//该函数用来释放分配给参数mutex 的资源。调用成功时返回值为
//0, 否则返回一个非0 的错误代码。

int pthread_cond_init(
                  pthread_cond_t *cond,
                  const pthread_cond_attr_t*attr
                  );
//该函数按参数attr指定的属性创建一个条件变量。调用成功返回,
//并将条件变量ID 赋值给参数cond,否则返回错误代码。

int pthread_cond_wait (
                   pthread_cond_t *cond ,
                   pthread_mutex_t*mutex
                   );
// 该函数调用为参数mutex 指定的互斥体解锁,等待一个事件(由
//参数cond 指定的条件变量)发生。调用该函数的线程被阻塞直到有其他
//线程调用pthread_cond_signal 或pthread_cond_broadcast 函数置相应的条
//件变量,而且获得mutex 互斥体时才解除阻塞。

int pthread_cond_timewait(
                      pthread_cond_t *cond ,
                      pthread_mutex_t*mutex ,
                      const struct timespec *abstime
                      );
// 该函数与pthread_cond_wait 不同的是当系统时间到达abstime 参数指定的时间时,被阻塞线程也可以被唤起继续执行。

int pthread_cond_broadcast(
                       pthread_cond_t *cond
                       );
// 该函数用来对所有等待参数cond所指定的条件变量的线程解除阻塞,调用成功返回0,否则返回错误代码。

int pthread_cond_signal(
                    pthread_cond_t *cond
                    );
// 该函数的作用是解除一个等待参数cond所指定的条件变量的线程的阻塞状态。当有多个线程挂起等待该条件变量,也只唤醒一个线程。

int pthread_cond_destroy(
                     pthread_cond_t *cond
                     );

// 该函数的作用是释放一个条件变量。释放为条件变量cond 所分配的资源。调用成功返回值为0,否则返回错误代码。

int pthread_key_create(
                   pthread_key_t key ,
                   void(*destructor(void*))
                   );

// 该函数创建一个键值,该键值映射到一个专有数据结构体上。如果第二个参数不是NULL,这个键值被删除时将调用这个函数指针来释放数据空间。

int pthread_key_delete(
                   pthread_key_t *key
                   );
// 该函数用于删除一个由pthread_key_create 函数调用创建的TSD键。调用成功返回值为0,否则返回错误代码。

int pthread_setspecific(
                    pthread_key_t key ,
                    const void(value)
                    );
// 该函数设置一个线程专有数据的值,赋给由pthread_key_create 创建的TSD 键,调用成功返回值为0,否则返回错误代码。

void *pthread_getspecific(
                    pthread_key_t *key
                    );

// 该函数获得绑定到指定TSD 键上的值。调用成功,返回给定参数key 所对应的数据。如果没有数据连接到该TSD 键,则返回NULL。

int pthread_once(
             pthread_once_t* once_control,
             void(*init_routine)(void)
             );
//该函数的作用是确保init_routine 指向的函数,在调用pthread_once的线程中只被运行一次。once_control 指向一个静态或全局的变量。