Is event autoreset operation atomic?

  • Thread starter Thread starter Kürþat
  • Start date Start date
K

Kürþat

Hi all,

I have a named autoreset event (EventWaitHandle) and two applications one
waits on the event and one sets the evet. Application A calls Set method and
free a thread in application B. What I want to know is when Set method
returns can I assume event is certainly reset?

Is this ordering always true :

1- Application A calls Set method (No doubt)
2- Application B gets out of lock (2 or 3 or uncertain)
3- Set method returns (2 or 3 or uncertain)
4- Event is certainly reset now (?)

Thanks in advance.
 
Hello, Kursat!

AFAIK Set can exit before or after thread release.

Why do you care if its atomic?

IMO Set changes event object's state atomically, so there is no need to worry
about Set method itself.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hi Vadym,

I try to set up a synchronization logic like this :

Thread A :
evt.Set (); // Release Thread B.
evt.WaitOne (); // Wait Thread B to complete.
// Thread B complete its job, go on

Thread B :
evt.WaitOne (); // Wait Thread A
doSomething ();
evt.Set (); // Job is done, release Thread A.

Initially Thread B waits Thread A to signal event. When Thread A signals
event, Thread B does something and Thread A waits on same event. After
Thread B completes its job it signals event and releases Thread A. Thus
Thread A knows when Thread B completes. This logic runs correctly only if
the event is certainly reset just after Set returns.

This is like SignalAndWait but only one WaitHandle used.
 
Hello, Kursat!

[skipped]

K> Initially Thread B waits Thread A to signal event. When Thread A signals
K> event, Thread B does something and Thread A waits on same event. After
K> Thread B completes its job it signals event and releases Thread A. Thus
K> Thread A knows when Thread B completes. This logic runs correctly only
K> if the event is certainly reset just after Set returns.

Logic you've set up is correct Do you observe other results?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hello Vadym,
It seems correct but observations are not enough to decide because, you
know, threads have random behaviors. So I think I must be sure about it
before use.

Thank you for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top