当前位置:网站首页>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传入的毫秒数
边栏推荐
猜你喜欢
指纹浏览器在使用易路代理时常见的问题及解决办法
共享静态IP与独享静态ip有何区别
背包问题 c语言版
Unity的GetComponentsInChildren1、2、3
Talking about 3 common shadow rendering techniques in games (2): shadow cone
Unity plug-in DOTween User Guide 2 (Brief explanation of Bezier curves)
Unity插件DOTween使用指南2(简释贝塞尔曲线)
UnityShader入门精要-立方体纹理、反射、折射、菲涅尔反射
多线程与多进程(概念详细讲解)
Talking about 3 Common Shadow Rendering Techniques in Games (3): Shadow Mapping
随机推荐
Analysis of minix_super_block.s_ninodes of mkfs.minix.c
计算数字区间中数字出现次数
动态规划、背包问题 6/26 116-120
Easy to master Unity of eight prior to rendering
OpenGL学习笔记(LearnOpenGL)-第二部分 绘制三角形
背包问题 c语言版
21天学习挑战赛--分班
手机与雷电模拟器里如何使用YiLu代理?
LaTeX总结----在CSDN上写出数学公式
KDE框架介绍
MySQL 免安装版/解压版的安装与配置(Win & Unix & Linux)
C#热更新比Lua好在哪里?
浅谈游戏中3种常用阴影渲染技术(1):平面阴影
21天学习挑战赛--字符串切割
markdown使用技巧
屏幕后期处理之:Sobel算子实现边缘检测
markdown类图学习
剑指 Offer(第 2 版)7/4 1-4
Unity热更新哪些事
废酸回收再利用