c# - How to substitute at runtime the WaitHandle that a thread should wait on -


i'm wondering how safely change @ runtime eventwaithandle thread should wait on.

suppose instance there 2 threads (a , c) synchronized through eventwaithandles. job cyclically , c waits until receives notification can start doing job (e.g. autoresetevent). pattern a-c-a-c...

later on new thread (b) launched (e.g. user action) , job should executed in between 2 preexistent threads in way: makes job, signals b , once b finishes signals c. pattern a-b-c-a-b-c...

so before thread c waiting on eventwaithandle shared , later there should safe mechanism makes c waiting on eventwaithandle shared b. seems me tricky part substituting eventwaithandle used c, since once done should able launch b use eventwaithandle wait on job , eventwaithandle signal c job. mechanism should provide way safely unmount thread b , go initial situation thread , c working.

is there safe way accomplish eventwaithandle ? if not, other suggestion appreciated.

if task knows change, have task c own event. task signals task c's event if c next, or task b's event if task b next.

alternatively, use same mechanism changing other shared data: acquire mutex across accesses handle. e.g. task c acquires lock, reads handle, releases lock, waits on handle. change have ui thread acquire lock, change handle, release lock.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -