当前位置:网站首页>pthread编程重要知识点
pthread编程重要知识点
2022-08-10 05:38:00 【denglin12315】
一. pthread_exit() 和 return的使用
The pthread_join() primitive, shown on line 24, is analogous to the fork-join wait() primitive. It blocks until the thread specified by the tid variable completes execution, either by invoking pthread_exit() or by returning from the thread’s top-level function.
The thread’s exit value will be stored through the pointer passed as the second argument to pthread_join(). The thread’s exit value is either the value passed to pthread_exit() or the value returned by the thread’s top-level function, depending on how the thread in question exits.
二.如果在pthread环境中要让多个线程在同一时刻同时获取同一把锁,如何实现?
What if I want several threads to hold the same lock at the same time?
The first thing you should do is to ask yourself why you would want to do
such a thing. If the answer is “because I have a lot of data that is read by many
threads, and only occasionally updated”, then POSIX reader-writer locks
might be what you are looking for. These are introduced in Section 4.2.4.
Another way to get the effect of multiple threads holding the same lock
is for one thread to acquire the lock, and then use pthread_create() to
create the other threads. The question of why this would ever be a good idea
is left to the reader.
三.poll的用法
poll(NULL, 0 , 毫秒数); //这种用法其实就是为了将当前线程block传入的毫秒数
边栏推荐
猜你喜欢
随机推荐
qemu and host share disk
mysql连接报错:Cannot get a connection, pool error Timeout waiting for idle object
Unity热更新哪些事
废酸回收再利用
氨氮的有效吸附材料
优先级队列,大小顶堆PriorityQueue
溶液中重金属去除
浅谈游戏中3种常用阴影渲染技术(3):阴影贴图
Myunity框架笔记
OpenGL学习笔记(LearnOpenGL)-第六部分 变换
Unity2d自动寻路(AI插件)
视差映射:更逼真的纹理细节表现(上):为什么要使用视差映射
电路分析中的电容器的基本知识
二叉树 6/21 91-95
unity守则(随时持续更新\自我总结)
ArgumentException: GetComponent requires that the requested component ‘GameObject‘ derives from Mono
Teach you to change the kernel source code--sysfs virtual file system 2
背包问题 c语言版
酸阻滞树脂
socket实现进程间通信