zoukankan      html  css  js  c++  java
  • Linux线程相互排斥量--进程共享属性

    多线程中。在相互排斥量和 读写锁的 属性中。都有一个叫 进程共享属性 。

    对于相互排斥量,查询和设置这个属性的方法为:
    pthread_mutexattr_getpshared
    pthread_mutexattr_setpshared

    我一開始不理解什么是 进程共享属性。 看了man中的说明例如以下

    The pthread_mutexattr_getpshared() function shall obtain the value of the process-shared attribute from the attributes object referenced by attr. The pthread_mutexattr_setpshared() function shall set the process-shared attribute in an initialized attributes object referenced by attr.

    The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a mutex to be operated upon by any thread that has access to the memory where the mutex is allocated, even if the mutex is allocated in memory that is shared by multiple processes. If the process-shared attribute is PTHREAD_PROCESS_PRIVATE, the mutex shall only be operated upon by threads created within the same process as the thread that initialized the mutex; if threads of differing processes attempt to operate on such a mutex, the behavior is undefined. The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE.

    意思是:
    这个属性有两个值
    PTHREAD_PROCESS_SHARED
    PTHREAD_PROCESS_PRIVATE, 顾名思义。是进程共享,和进程不共享。 也即是 当你的进程初始化一个相互排斥量后, 是仅仅有自己的进程 能够使用,还是 其它进程也能够使用这个相互排斥量。


    默认情况是 PTHREAD_PROCESS_PRIVATE。 仅仅有本进程能够 对这个相互排斥量加锁等操作。
    这时。别的进程。对私有的 相互排斥量 操作的行为。未定义。

  • 相关阅读:
    hbase删除标记和注意事项
    马上拥有一台自己的云服务器
    在 Ubuntu 开启 GO 程序编译之旅
    在 Ubuntu 上安装 Protobuf 3
    功能设计中技术人员之惑
    关于数据可视化页面制作
    快速响应请求浅谈
    自定义一个代码耗时计数工具类
    一种极简的异步超时处理机制设计与实现(C#版)
    百度地图API图标、文本、图例与连线
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7141020.html
Copyright © 2011-2022 走看看