初始化临界区

(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对比相关推荐

  1. api有哪些 javasocket_简单hello/hi程序、分析及Java Socket API与Linux Socket API对比

    1.Socket 定义 套接字(socket)是一个抽象层,应用程序可以通过它发送或接收数据,可对其进行像对文件一样的打开.读写和关闭等操作.套接字允许应用程序将I/O插入到网络中,并与网络中的其他应 ...

  2. linux bochs 网卡,Bochs 在Windows和Linux下配置对比

    Bochs是一个x86硬件平台的开源模拟器.它可以模拟各种硬件的配置.Bochs模拟的是整个PC平台,包括I/O设备.内存和BIOS.更为有趣的是,甚至可以不使用PC硬件来运行Bochs.事实上,它可 ...

  3. linux线程并不真正并行,多核时代:并行程序设计探讨(3)——Windows和Linux对决(多进程多线程)...

    并行程序设计探讨(3)--Windows和Linux对决(多进程多线程) 前面的博文经过分析总结,最后得出两种并行技术:多进程多线程.多机协作.对于多进程和多线程来说,最有代表性且最常见的的莫过于Wi ...

  4. windows linux 融合,Windows和Linux的设备驱动框架的对比融合研究

    摘要:把驱动框架分为三层,针对各层在Windows和Linux中的实现方法的不同,对Windows和Linux的设备驱动框架进行对比研究.从接口函数,应用程序访问驱动程序的路径,驱动程序具体实现及安装 ...

  5. Windows 下目录及文件向Linux同步

    本文解决的是Windows 下目录及文件向Linux同步的问题,Windows向 Windows同步的请参考:http://www.idcfree.com/article-852-1.html 环境介 ...

  6. Linux上搭建Samba,实现windows与Linux文件数据同步

    一 环境介绍 1. 本地win10 2. Linux (centos7.4) 注:因为运营商方面禁止smb协议,导致无法在云服务器上使用smb,如果不是在虚拟机上操作,而是在云服务器上操作,建议还是使 ...

  7. windows如何调用Linux的API,Windows和Native API中的系统调用?

    最近,我在* NIX操作系统中使用了很多汇编语言.我想知道Windows域. Linux中的调用约定: mov $SYS_Call_NUM, %eax mov $param1 , %ebx mov $ ...

  8. Windows和Linux VPS/GDrive之间文件夹的实时单向/双向同步教程

    说明:一般我们同步Windows和Linux之间的文件时,常用的方法有nfs挂载,inotify + rsync同步等,有钱的或许会买成熟的storenext系统,当然后者基本上都是公司在用,stor ...

  9. Windows与Linux的命令行命令对比

    Windows与Linux的命令行命令对比 * Windows不区分大小写,Linux区分大小写的. sn DOS Command UNIX Equivalent Effect 影响 1 ASSIGN ...

最新文章

  1. 递归函数 集合 列表 元组
  2. linux内核远程漏洞,CVE-2019-11815:Linux内核竞争条件漏洞导致远程代码执行
  3. ping命令工具:同时ping多个IP
  4. 2019年上半年收集到的AI计算机视觉方向干货文章
  5. ASP.NET 2.0+Atlas编写鼠标拖放程序(2)
  6. [蓝桥杯][算法提高VIP]密码锁(BFS)
  7. python psutil替代_Python2.7 psutil模块
  8. 基于JAVA+SpringBoot+Mybatis+MYSQL的旅游网站系统
  9. Python封装的获取文件目录的函数
  10. 什么是 Servlet 容器?
  11. gitbub 上删除仓库
  12. 会计信息质量可靠性的案例_论会计信息质量特征及其可靠性
  13. 辨别身份真假之【天眼数聚】腾讯云身份证实名认证接口
  14. 《Flutter 控件大全》第五十五个:InkWell和Ink
  15. win10彻底禁用自动更新,win10怎样彻底关闭自动更新,永久关闭win10自动更新,win10更新助手...
  16. 我喜欢邓丽君,死掉了;
  17. 普通人卖什么才能赚到人生的第一桶金?
  18. 美国印第安纳大州Purdue(普杜)大学的法国数学家Louis de Branges de Bourcia周二表示已经证明了黎曼猜想
  19. 累加器 java_Spark笔记之累加器(Accumulator)
  20. 【Linux入门指北】Linux实验综合训练

热门文章

  1. Mac提示app损坏、Error,Mac电脑最常见错误的解决方案
  2. linux6.5能安装的firefox,Centos6.5安装firefox
  3. 《信息学奥赛一本通 提高篇》
  4. 算法与数据结构 设计模式
  5. 德芙网络营销策略ppt_德芙网络营销方案
  6. python安装轮子_如何安装这个轮子?
  7. win7怎么进入安全模式_windows 10如何进入安全模式
  8. Nacos笔记-对Nacos初步认识
  9. Flask笔记-使用Cookie及简单加密判断是否为登录用户
  10. 前端工作笔记-Nginx安装及vue cli部署