VOOZH about

URL: https://www.geeksforgeeks.org/c/print-1-2-3-infinitely-using-threads-in-c/

⇱ Print 1 2 3 infinitely using threads in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print 1 2 3 infinitely using threads in C

Last Updated : 22 Jul, 2019
Print 1 2 3 infinitely using thread. Create three threads viz T1, T2, and T3 such that those should print 1 2 3 sequence infinitely. Examples :
Output :1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ......
Prerequisite : Threads in C Approach :
  • Start an infinite loop and initialize a variable 'done' to 1.
  • Now, check for the value of done is not equal to 1.
  • If it is hold wait condition lock, else print n and respectively signal the next consecutive n.
Output :
1 2 3 1 2 3 1 2 3 1 2 3 ...
Comment