Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a non blocking semaphore?

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

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

like image 670
Lazer Avatar asked Aug 04 '12 00:08

Lazer


People also ask

What is a non-blocking process?

In computer science, an algorithm is called non-blocking if failure or suspension of any thread cannot cause failure or suspension of another thread; for some operations, these algorithms provide a useful alternative to traditional blocking implementations.

What is blocking and non-blocking?

Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn't block execution. Or as Node. js docs puts it, blocking is when the execution of additional JavaScript in the Node. js process must wait until a non-JavaScript operation completes.

What is blocking semaphore?

a blocking semaphore is initialised to zero rather than one. You set the initial number of permits. If you set permits to 1 ( new Semaphore(1) ), you can acquire once before you release . If the value is > 0 , some acquire s may happen before release s.

What do you mean by non-blocking I O?

Non-blocking I/O avoids the client being blocked while waiting for a request to be accepted by the transport layer during one-way messaging for connection-oriented protocols. For connection-oriented protocols, there is a limit to the amount of data that can be put in a network protocol queue.


1 Answers

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

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.

like image 173
nos Avatar answered Nov 15 '22 06:11

nos