初始化临界区

(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. 【av68676164(p31-p32)】Windows和Linux同步机制

    4.6.1 Windows同步机制 临界区(CRITICAL_SECTION) 在进程内使用,保证仅一个线程可以申请到该对象 临界区内是临界资源的访问 相关的API函数 初始化临界区 WINBASEA ...

  2. windows、Linux同步外网NTP服务器时间

    配置 Windows 时间服务以使用外部时间源 要将内部时间服务器配置为与外部时间源同步,请使用以下方法之一: 软件自动配置  Windows 时间服务 若要自动修复此问题,请单击“下载”按钮. 在“ ...

  3. rsync在windows和linux同步数据的配置过程

    centos7.0安装rsync3.0.9-17.el7 yum install rsync ===================================================== ...

  4. [转帖]Windows和Linux对决(多进程多线程)

    Windows和Linux对决(多进程多线程) https://blog.csdn.net/world_2015/article/details/44920467 太长了 还没看完.. 还是没太理解好 ...

  5. Linux与Windows的设备驱动模型对比

    Linux与Windows的设备驱动模型对比 名词缩写: API 应用程序接口(Application Program Interface ) ABI 应用系统二进制接口(Application Bi ...

  6. Windows 和 Linux 的IPC API对应表

    原文出处:http://blog.csdn.net/zhengdy/article/details/5485472                                           ...

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

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

  8. linux同步windows的时间

    找了很多的资料,都没有windows做时间服务,linux同步windows的时间的,最后自己找了一些软件,终于搞定了,写出来给大家共享,以免大家多走弯路 首先在http://www.meinberg ...

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

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

随机推荐

  1. Win32多线程编程(3) — 线程同步与通信

      一.线程间数据通信 系统从进程的地址空间中分配内存给线程栈使用.新线程与创建它的线程在相同的进程上下文中运行.因此,新线程可以访问进程内核对象的所有句柄.进程中的所有内存以及同一个进程中其他所有线 ...

  2. Linux的目录结构及其作用

    /bin bin是Binary的缩写.这个目录存放着最经常使用的命令. /boot这里存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件. /dev dev是Device(设备) ...

  3. Impala 源码分析-FE

    By yhluo 2015年7月29日 Impala 3 Comments Impala 源代码目录结构 SQL 解析 Impala 的 SQL 解析与执行计划生成部分是由 impala-fronte ...

  4. Struts2上传文件

    jsp: <form action="file_upload.action" method="post" enctype="multipart/ ...

  5. 限制内容长度(CSS,jQuery)

    CSS(宽度限制在100px之内,超出就会点点点) <style type="text/css"> p{width: 100px;display: inline-blo ...

  6. (转)SQL Server2005 异常处理机制(Begin try Begin Catch)

    begin try --SQL  end trybegin catch --sql (处理出错动作) end catch我们将可能会出错的sql 写在begin try...end try 之间,若出 ...

  7. 我永远的 dell 15r

    陪伴我三年多的15r  让我疯狂过.努力过.更记录了我很多的成长,与很多个瞬间.看到它是有感情的.还记得第一次失去她.我好像失去了自己. 我是一个程序员.每个程序员都有自己的环境配置.不同的软件.就是 ...

  8. 洛谷 P3367 【模板】并查集

    P3367 [模板]并查集 题目描述 如题,现在有一个并查集,你需要完成合并和查询操作. 输入输出格式 输入格式: 第一行包含两个整数N.M,表示共有N个元素和M个操作. 接下来M行,每行包含三个整数 ...

  9. C++Primer笔记(2)

    大型程序一般都是分为多个模块,由多人协作来进行开发的,其中还不可避免的会用到库.而各个模块代码以及库中会定义大量变量,而大量变量的命名,不可避免的会遇见“重名”的问题.“重名”的情况我们称之为命名空间 ...

  10. Java如何获取当前的jar包路径以及如何读取jar包中的资源

    写作业的时候要输出一个record.dat文件到jar包的同级目录,但是不知道怎么定位jar包的路径.百度到的方法不很靠谱,所以在这里记录一下. 一:使用类路径 String path = this. ...