Linux 信号量sem_post(3)(翻译 man 3)

来源:互联网 发布:内网聊天软件 编辑:程序博客网 时间:2024/05/18 09:02
SEM_POST(3)                   Linux Programmer's Manual                   SEM_POST(3)

NAME

       sem_post - unlock a semaphore
//解锁一个信号量

SYNOPSIS

       #include 
    int sem_post(sem_t *sem);
       Link with -lrt or -pthread.

DESCRIPTION

       sem_post() increments (unlocks) the semaphore pointed to by sem.  If the       semaphore's value consequently becomes greater than zero, then another process       or thread blocked in a sem_wait(3) call will be woken up and proceed to lock       the semaphore.
//sem_post() 增加(解锁)由sem指向的信号量的值.如果信号量的值因此比0大,那么另一个阻塞在sem_wait(3)上的进程或线程的调用就会被唤醒,之后锁定这个信号量.
//(译者注:因为sem_wait会使得信号量减一,开始阻塞在sem_wait()的线程当信号量sem_post()之后(信号量加一)就会被唤醒,执行之后又会被阻塞(因为信号量此时为0)).

RETURN VALUE

       sem_post() returns 0 on success; on error, the value of the semaphore is left       unchanged, -1 is returned, and errno is set to indicate the error.
//成功返回0,失败信号量的值不会改变,返回-1,并自动设置errno.

ERRORS

       EINVAL sem is not a valid semaphore.//sem不是有效的信号量       EOVERFLOW              The maximum allowable value for a semaphore would be exceeded.
//信号量允许的最大值已经超过了.

CONFORMING TO

       POSIX.1-2001.

NOTES

       sem_post() is async-signal-safe: it may be safely called within a signal       handler.
//sem_post()是异步信号安全的:在信号处理程序内调用它是安全的.

EXAMPLE

       See sem_wait(3).

SEE ALSO

       sem_getvalue(3), sem_wait(3), sem_overview(7)

COLOPHON

       This page is part of release 3.31 of the Linux man-pages project.  A       description of the project, and information about reporting bugs, can be found       at http://www.kernel.org/doc/man-pages/.Linux                                 2009-03-30                          SEM_POST(3)
原创粉丝点击