什么是非阻塞信号量?

时间:2022-10-23 20:27:27

Seems like a contradiction because a semaphore should block to function.

似乎是矛盾,因为信号量应该阻止功能。

Internet searches do not show up anything useful towards defining what this means.

互联网搜索没有显示出对定义这意味着什么有用的东西。

3 个解决方案

#1


7  

If a semaphore has the value 0, a down operation on it will block until someone releases a resource and increments the semaphore.

如果信号量的值为0,则对其进行向下操作将阻塞,直到有人释放资源并递增信号量为止。

A non-blocking semaphore does not block on a down operation if the resource is unavailable, but rather yields an error. This can be useful if the program needs that resource immediately or without suspending execution, and if the resource isn't available, the program logic can rather do something else.

如果资源不可用,则非阻塞信号量不会阻止向下操作,而是产生错误。如果程序立即需要该资源或没有暂停执行,这可能很有用,如果资源不可用,程序逻辑可以做其他事情。

#2


5  

A non-blocking semaphore typically refers to a semaphore which allows you to try to acquire without blocking. If the semaphore can't be "locked", then it will fail but not block. If it can be locked, it will lock it and return true (that it locked).

非阻塞信号量通常是指信号量,它允许您尝试获取而不会阻塞。如果信号量不能被“锁定”,那么它将失败但不会阻塞。如果它可以被锁定,它将锁定它并返回true(它被锁定)。

#3


1  

The associated wait operation WaitForSingleObject() for example allows to specify a timeout value dwMilliseconds. If this parameter is set to 0 the result of the call will always return immedeately. This way the state of a semaphore can be tested without blocking.

例如,相关的等待操作WaitForSingleObject()允许指定超时值dwMilliseconds。如果此参数设置为0,则调用的结果将始终立即返回。这样,可以在不阻塞的情况下测试信号量的状态。

#1


7  

If a semaphore has the value 0, a down operation on it will block until someone releases a resource and increments the semaphore.

如果信号量的值为0,则对其进行向下操作将阻塞,直到有人释放资源并递增信号量为止。

A non-blocking semaphore does not block on a down operation if the resource is unavailable, but rather yields an error. This can be useful if the program needs that resource immediately or without suspending execution, and if the resource isn't available, the program logic can rather do something else.

如果资源不可用,则非阻塞信号量不会阻止向下操作,而是产生错误。如果程序立即需要该资源或没有暂停执行,这可能很有用,如果资源不可用,程序逻辑可以做其他事情。

#2


5  

A non-blocking semaphore typically refers to a semaphore which allows you to try to acquire without blocking. If the semaphore can't be "locked", then it will fail but not block. If it can be locked, it will lock it and return true (that it locked).

非阻塞信号量通常是指信号量,它允许您尝试获取而不会阻塞。如果信号量不能被“锁定”,那么它将失败但不会阻塞。如果它可以被锁定,它将锁定它并返回true(它被锁定)。

#3


1  

The associated wait operation WaitForSingleObject() for example allows to specify a timeout value dwMilliseconds. If this parameter is set to 0 the result of the call will always return immedeately. This way the state of a semaphore can be tested without blocking.

例如,相关的等待操作WaitForSingleObject()允许指定超时值dwMilliseconds。如果此参数设置为0,则调用的结果将始终立即返回。这样,可以在不阻塞的情况下测试信号量的状态。