There are times when one thread waits on a signal from another and vice versa. This is called two-way signaling. Learn how to implement two-way signaling using AutoResetEvent.
- [Instructor] We just saw how to use…an event wait handle of type auto reset event.…Now, we're going to see how two-way signaling can work.…It's very similar except this time,…we will have a little bit more interaction between…both the threads.…So for example, main thread will be waiting while…the worker thread will be updating a value…and then it would release the main thread.…And I will do the same exact thing…by just reversing that order.…
So quite simply, we need to start with an event wait handle…and resolve this using System.Threading.…I'm just going to call it first,…and this time we'll use the easy way out.…Auto reset event and initial state is going to be false…and that means it's not going to be signaled.…And then we can create a similar one…and we'll call this one second.…
Now this is where we can say Task.Factory.StartNew…and start the worker thread.…Again, this is a method and you call it something else.…The reason I call it WorkerThread is so we know…which thread is getting called.…Resolved the method.…
Released
4/2/2018- Thread safety and affinity
- Signaling
- Task Parallel Library (TPL) basics
- PLINQ introduction
- Task-based Asynchronous Pattern (TAP)
Share this video
Embed this video
Video: Two-way signaling