windows 和linux 同步api对比
初始化临界区
(win)
InitializeCriticalSection(RTL_CRITICAL_SECTION &rtl_critial_section)
(linux)
pthread_mutexattr_init(&(mutex)->attr);
pthread_mutexattr_settype(&(mutex)->attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&(mutex)->mtx, &(mutex)->attr);
删除临界区
(win)
DeleteCriticalSection(RTL_CRITICAL_SECTION &)
(linux)
pthread_mutex_destroy(pthread_mutex_t &mutex)
进入临界区
(win)
EnterCriticalSection(RTL_CRITICAL_SECTION &rtl_critical_section)
(linux)
pthread_mutex_lock(pthread_mutex_t &mutex)
尝试进入临界区
(win)
TryEnterCriticalSection(RTL_CRITICAL_SECTION &rtl_critical_section )
(linux)
pthread_mutex_trylock(pthread_mutex_t &mutex)
离开临界区
(win)
LeaveCriticalSection(RTL_CRITICAL_SECTION &rtl_critical_section )
(linux)
pthread_mutex_unlock(pthread_mutex_t &mutex)
把目标操作数(第1参数所指向的内存中的数)与一个值(第3参数)比较,如果相等,则用另一个值(第2参数)与目标操作数(第1参数所指向的内存中的数)交换;InterlockedExchange是不比较直接交换。整个操作过程是锁定内存的,其它处理器不会同时访问内存,从而实现多处理器环境下的线程互斥
(win)
InterlockedCompareExchange(Destination, newvalue, oper)
(linux)
__sync_val_compare_and_swap(Destination, oper, newvalue)
v的值原子添加P的大小
(win)
InterlockedExchangeAdd(V, P)
(linux)
__sync_fetch_and_add(V, P)
原子增加一
(win)
InterlockedIncrement(T)
(linux)
__sync_fetch_and_add(T, 1)
原子减少一
(win)
InterlockedDecrement(T)
(linux)
__sync_fetch_and_sub(T, 1)
获取当前线程id
(win)
GetCurrentThreadId()
(linux)
syscall(SYS_gettid)
如果指定一个非零值,函数处于等待状态直到hHandle 标记的对象被触发,或者时间到了。如果dwMilliseconds 为0,对象没有被触发信号,函数不会进入一个等待状态,它总是立即返回。如果dwMilliseconds 为INFINITE,对象被触发信号后,函数才会返回。对应的linux实现使用条件变量
(win)
WaitForSingleObject(event,INFINITE)
(linux)
pthread_mutex_lock( &m_tx );
pthread_cond_wait( &event, &m_tx );
pthread_mutex_unlock( &m_tx );
退出线程(退出参数0)
(win)
ExitThread(0)
(linux)
pthread_exit(0)
设置线程优先级,pthread_setschedparam在多线程开发中经常被使用的,它主要用于设置线程的调用策略和优先级
(win)
SetThreadPriority (handle,nPrioroty)
(linux)
sched_param sp = {nPriority};
if(0 == pthread_setschedparam(m_pid, SCHED_RR, &sp))
{
return true;
}
return false;
获取优先级
(win)
GetThreadPriority( Handle m_hThread )
(linux)
int policy;
sched_param sp;
pthread_getschedparam(m_pid, &policy, &sp))
sp.sched_priority;
初始化互斥量
(linux)
pthread_mutex_init(pthread_mutex_t &mutex),0)
初始化条件变量
pthread_cond_init(&cond,0)
删除互斥量
pthread_mutex_destroy(pthread_mutex_t &mutex))
删除条件变量
(linux)
pthread_cond_destroy(pthread_cond_t &cond)
向条件变量发起信号
(linux)
pthread_cond_signal(pthread_cond_t &cond)
挂起等待结束(无限等待) true在阻塞期间允许进入警告状态(windows才有)
(win)
WaitForSingleObject Ex(handle, INFINITE,true)
(linux)
pthread_join (pthread_t thid, void ** ret_val) 常用pthread_join(pid,0)
windows 和linux 同步api对比的更多相关文章
- 【av68676164(p31-p32)】Windows和Linux同步机制
4.6.1 Windows同步机制 临界区(CRITICAL_SECTION) 在进程内使用,保证仅一个线程可以申请到该对象 临界区内是临界资源的访问 相关的API函数 初始化临界区 WINBASEA ...
- windows、Linux同步外网NTP服务器时间
配置 Windows 时间服务以使用外部时间源 要将内部时间服务器配置为与外部时间源同步,请使用以下方法之一: 软件自动配置 Windows 时间服务 若要自动修复此问题,请单击“下载”按钮. 在“ ...
- rsync在windows和linux同步数据的配置过程
centos7.0安装rsync3.0.9-17.el7 yum install rsync ===================================================== ...
- [转帖]Windows和Linux对决(多进程多线程)
Windows和Linux对决(多进程多线程) https://blog.csdn.net/world_2015/article/details/44920467 太长了 还没看完.. 还是没太理解好 ...
- Linux与Windows的设备驱动模型对比
Linux与Windows的设备驱动模型对比 名词缩写: API 应用程序接口(Application Program Interface ) ABI 应用系统二进制接口(Application Bi ...
- Windows 和 Linux 的IPC API对应表
原文出处:http://blog.csdn.net/zhengdy/article/details/5485472 ...
- Windows 下目录及文件向Linux同步
本文解决的是Windows 下目录及文件向Linux同步的问题,Windows向 Windows同步的请参考:http://www.idcfree.com/article-852-1.html 环境介 ...
- linux同步windows的时间
找了很多的资料,都没有windows做时间服务,linux同步windows的时间的,最后自己找了一些软件,终于搞定了,写出来给大家共享,以免大家多走弯路 首先在http://www.meinberg ...
- Windows与Linux的命令行命令对比
Windows与Linux的命令行命令对比 * Windows不区分大小写,Linux区分大小写的. sn DOS Command UNIX Equivalent Effect 影响 1 ASSIGN ...
随机推荐
- vsim生成VCD波形文件(verilog)
Vsim(ModelSim)生成VCD波形文件(verilog) 两种方法 方法一: 调用ModelSim自己的命令生成,仿真脚本中加入如下一句即可 vcd file mytb.vcd 方法二: 调用 ...
- compass安装
修改ruby软件包的sources 国外服务器不给力,经常链接失败,换成国内淘宝的:https://ruby.taobao.org/ 先移除本有的sources gem sources --remov ...
- .net的WebForm模拟MVC进行模型绑定,让自己少操劳
一.前言 用过MVC的兄弟们都知道,MVC有模型绑定表单提交的数据功能,那么我也想偷个懒也写个WebForm版的模型绑定.这里主要定义一个泛型方法,然后通过反射把表单上对应属性名字的值赋值到反射创建类 ...
- Android--------- SD卡存储文件报错解决
##文件找不到 1.没有写write权限 2.没有判断文件夹是否存在,不存在则创建
- iOS_SN_BlueTooth( 一)蓝牙相关基础知识
原文 http://www.cocoachina.com/ios/20150915/13454.html 作者:刘彦玮 蓝牙常见名称和缩写 MFI ======= make for ipad ,ip ...
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- show_space/get_alert_log/get_trace_file
1.get_alert_log 获取alert文件的路径和名称 set serveroutput on --设置输出,让sqlplus在屏幕上可以输出.(要加入到login.sql中!) ...
- nignx开启expires后相关资源不显示的问题
expires可以指定浏览器缓存,加快浏览速度 但是开启expires必须先指定root server中原来指定 location / { root D:/WWW; index index.html ...
- 最大公约数(gcd):Euclid算法证明
1个常识: 如果 a≥b 并且 b≤a,那么 a=b. 2个前提: 1)只在非负整数范围内讨论两个数 m 和 n 的最大公约数,即 m, n ∈ N. 2)0可以被任何数整除,但是0不能整除任何数,即 ...
- js判断是手机访问还是电脑访问
<script type="text/javascript"> <!-- //平台.设备和操作系统 var syste ...