栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

LINUX下信号量的使用

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

LINUX下信号量的使用

首先通过man可以查看Linux下的信号量函数

// Linux信号量API函数
// int sem_init(sem_t *sem, int pshared, unsigned int value);
// int sem_destroy(sem_t *sem);
// int sem_post(sem_t *sem);
// int sem_wait(sem_t *sem);
// int sem_trywait(sem_t *sem); 
// int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); 有一点需要注意的是abs_timeout是绝对时间不是相对时间

下面有一个测试程序,测试了各个函数在调用时的表现

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 

static sem_t  sem1;
void Test1()
{
    while(true)
    {
        sem_wait(&sem1);
        std::cout<<"sem_wait"<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/599443.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号