In reply to SanjanaDhiran:
It should display:
0#####
1#####
1
2#####
2
3
Explanation:
Below Sequence will be followed-
- “0#####” will be executed first
- It will execute blocking statement #1
- Fork will be spawned but will not start
- “1#####” - will Execute the Display statement
- “1” - The Blocking statement has been executed it will execute the first spawn “1”
- “2#####” Will execute the display statement
- “2” - Blocking statement has been executed and will execute the next thread
- “3” All statements have been executed and will come out of the loop and display remaining
Thanks
Irshad