Skip to content
Advertisement

Linux scheduling. (pthreads)

I’m trying to play around with threads and so far, with the code below, I’m doing fine. I want also want to print the current index of the executing thread but I’ve encountered some problems.

JavaScript

I’m trying to print the current executing thread along with “Hello world!”. But, the output is this…

JavaScript

So far, I’ve already tried issuing

JavaScript

What can I tweak in the code to achieve my goal?

Advertisement

Answer

You forgot to put a block of statements in braces:

JavaScript

Multiple statements to be executed in for loop must be covered in braces otherwise only first of them is called, printf("Hi, I'm thread #%dn", i) in this case. Solution:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement