Barrier: synchronizes threads in freamwork 4
Question: How to build a barrier like a a traffic light for threads and synchronize them? Solution: That's what brought us to the barrier of framework 4 ! I built code that gets three threads and trying to sync. There are three types of situations: 1. Green - do not get their delayed and continue normal (driving). 2. Yellow - paused for a second and then goes through the green . 3. Red - delayed for 2 seconds and then goes through the yellow color. The following code shows a good example of a barrier. Sync object is a barrier. It causes delay by type situation. Join activates the trigger of the action ( TrafficLightsAction ). using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BarrierTrafficLights { class Program { ...