- #1
Nissen, Søren Rune
I have a friend that needs something done which I can't think of a non-threaded way to do, and we're having some trouble understanding how the pthread library works.
He wants a program to execute until he presses a button. I suggested having one thread with a while loop that runs until a variable is changed, and a different loop that reads into that variable from the keyboard. Is this even a good solution to the problem?
If it is a good solution, what's the scheduler like? The guide I'm reading right now says
He wants a program to execute until he presses a button. I suggested having one thread with a while loop that runs until a variable is changed, and a different loop that reads into that variable from the keyboard. Is this even a good solution to the problem?
If it is a good solution, what's the scheduler like? The guide I'm reading right now says
but that doesn't tell me what happens if I don't enable thread scheduling. I'm guessing the thread that executes first will then keep running until it's finished (which it never will) and the other one will be locked out but frankly I'm not sure at all.Thread Scheduling:
When this option is enabled, each thread may have its own scheduling properties. Scheduling attributes may be specified:
* during thread creation
* by dynamically by changing the attributes of a thread already created
* by defining the effect of a mutex on the thread's scheduling when creating a mutex
* by dynamically changing the scheduling of a thread during synchronization operations.
The threads library provides default values that are sufficient for most cases.