Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signalled and non-signalled state of event

This could be a non programming question to all,i did read about the thread synchronization objects such as event and how it is set as signalled or non-signalled state . However i couldn't understand these terms signalled and non-signalled .Each one has expressed in different ways and i'm bit confused.

  1. This link states that

    A signaled state indicates a resource is available for a process or thread to use it. A not-signaled state indicates the resource is in use.

  2. I got an power point presentation from an university site which states that

    An object that is in the signaled state will not cause a thread that is waiting on the object to block and object that is not in the signaled state will cause any thread that waits on that object to block until the object again becomes signaled.

  3. This third link states this

    An event is in signaled state means that it has the capacity to release the threads waiting for this event to be signaled. An event is in non signaled state means that it will not release any thread that is waiting for this particular event.

A simple explanation on this concept with an example would be really helpful.

like image 321
Santhosh Pai Avatar asked Jul 12 '13 10:07

Santhosh Pai


People also ask

What is the difference between signaled and non signaled states with Windows dispatcher objects?

7.5 Explain the difference between signaled and non-signaled states with Windows dispatcher objects. Answer: An object that is in the signaled state is available, and a thread will not block when it tries to acquire it. When the lock is acquired, it is in the non-signaled state.

What is event object in windows?

An event object is a synchronization object whose state can be explicitly set to signaled by use of the SetEvent function. Following are the two types of event object. Object. Description.


2 Answers

Easy way to think of it: "signalled" = "green light"

Green LightSignalled: If you're driving and you see a green light you don't stop (this is the thread looking at an event, finding it's signalled and carrying on without blocking).

Red LightNon-Signalled: If you see a red light you stop and wait for it to become green and then carry on (safe in the knowledge the other threads all are now non-signalled thus are waiting or will wait at their...red light!)

like image 128
noelicus Avatar answered Oct 01 '22 00:10

noelicus


Ok, your 3 quotes are not incompatible. But let's go a bit down to the implementation:

Every waitable object has a boolean value attached to it, named the signalled state, that is used to wait for that object; if the object is signalled, then the wait functions will not wait for it; if the object is non-signalled, then the wait functions will wait for it.

Now, how does this apply to a particular type of object? That depends on the objects nature and specifically on the semantics associated to waiting for it. Actually, the signalled state is defined in terms of wait condition. the For example (see the docs for details):

  • A mutex is signalled when it is not owned.
  • An process/thread is signalled when it has finished.
  • A semaphore is signalled when its count is greater than 0.
  • A waitable timer is signalled when it has expired.

You might like better if a mutex were signalled when owned, but actually it is when not owned. That's necessary to make the wait functions do the right thing.

And what about the events? Well, they are somewhat simple objects, you can signal and de-signal them at will, so the signal state has no additional meaning:

  • signalled: Threads will not wait for it.
  • non-signalled: Threads will wait for it.

Events also have this SignalPulse and AutoReset things that are a bit peculiar (and IME practically impossible to use right).

Now, let's look at your quotes:

A signaled state indicates a resource is available for a process or thread to use it. A not-signaled state indicates the resource is in use.

Actually, that is an interpretation. Usually there is a resource you are trying to arbitrate, and usually you wait if-and-only-if that resource is in use, so it is making the equivalence between resource-in-use and wait-for-resource. But that's not a technical requiremente, just a usual use-case.

An object that is in the signaled state will not cause a thread that is waiting on the object to block and object that is not in the signaled state will cause any thread that waits on that object to block until the object again becomes signaled.

Correct and to the point!

An event is in signaled state means that it has the capacity to release the threads waiting for this event to be signaled. An event is in non signaled state means that it will not release any thread that is waiting for this particular event.

I find this wording a bit confusing... but it adds nothing over the previous one.

like image 31
rodrigo Avatar answered Oct 01 '22 00:10

rodrigo