Pass the value of the indicator to indicate whether the stream should print an odd number or even a number through the stream function argument.
Depending on whether you start with 0 (for even numbers) or 1 (for odd numbers) and continue to increase by 2 both in streams and when printing. A.
You can also print the stream identifier along with the number to indicate which stream prints what.
I assume you know how to use pthreads.
[Refresh]: Link for pthreads Even with semaphores or mutexes, it’s difficult for you to get a result of 1,2,3, etc., since you never know which thread will be able to execute in the first place. To do this, you may need to use some advanced concepts, such as thread priority or cross-threading using conditional variables. These are just hints. I hope that if you follow the link, you will get more information.
source share