The problem is to synchronize n number of threads using pthread library. The idea is take thread count and print 1 in first thread, print 2 in second thread, print 3 in third thread, ….. print n in nth thread and again repeat from thread 1 infinitely.
Prerequisite : Multithreading
Input : Thread count Output : 1 2 3 ... thread count 1 2 3 ... thread count 1 2 3 ... thread count .... Input : 5 Output : 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 ....
Below is the implementation:
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 User Level thread and Kernel Level thread
- Running User Interface Thread in Android using Kotlin
- Thread in Operating System
- Get the stack size and set the stack size of thread attribute in C
- Thread joinable() function in C++
- Thread get_id() function in C++
- Thread hardware_concurrency() function in C++
- Thread functions in C/C++
- Thread States in Operating Systems
- Difference between Process and Kernel Thread
- How will you print numbers from 1 to 100 without using loop?
- C Program to print numbers from 1 to N without using semicolon?
- How will you print numbers from 1 to 100 without using loop? | Set-2
- Program to Print Pyramid Pattern using numbers
- Program to print a pattern of numbers
- Sequence Points in C | Set 1
- Write a C program to print "Geeks for Geeks" without using a semicolon
- How to print % using printf()?
- Print "Even" or "Odd" without using conditional statement
- Print a long int in C using putchar() only
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.
Improved By : jeff1jeffo