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.
Output :1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ......
Prerequisite : Threads in C
- 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.
1 2 3 1 2 3 1 2 3 1 2 3 ...
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference Between Daemon Threads and User Threads In Java
- Two way communication between Client and Server using Win32 Threads
- C++ File Writer-Reader application using Windows Threads
- Maximum number of threads that can be created within a process in C
- Introducing Threads in Socket Programming in Java
- Sharing a queue among three threads
- Print numbers in sequence using thread synchronization
- Merge Sort using Multi-threading
- Sum of an array using pthreads
- Maximum element in a very large array using pthreads
- Linear search using Multi-threading
- Using fork() to produce 1 parent and its 3 child processes
- Maximum in a 2D matrix using Multi-threading in C++
- Determinant of N x N matrix using multi-threading
- Odd Even Transposition Sort / Brick Sort using pthreads
- Chat application between two processes using signals and shared memory
- Frequency of a substring in a string using pthread
- Running User Interface Thread in Android using Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.