Threading...

Sorry, i may be posting the wrong question in this forum... but just curious, suppose we have a set of pre-emptively scheduled processes. A process, B, is multi-threaded with user-level thread scheduling. If one of the threads has a long calculation before making a thread library call, does this mean other processes will have to wait? What happens in the schedulers?

In UNIX, you can generally think of a thread as a process that has its own stack for registers but shares code and data with the parent process - and the other threads.

For that reason, thread scheduling can be implemented a lot like process scheduling - ie, there is usually a quantum (time slice) allocated to a process/thread that has the cpu -- threading works much more efficiently in a multi-cpu environment. When the quantum is up and somebody else wants the cpu and is of equal priority, the other guy gets the cpu. Any thread or process with higher priority will pre-empt the cpu from the running process.

So, the answer to your question is: assuming all threads have equal priority - no the other guys will not have to wait. Unless the calculating thread has a mutex the other guys are waiting on. You can implement single-thread priority by using a mutex in other words.

Try man pthread to see what thread scheduling options (if more than one) your implementation of UNIX supports.

wow, thanks jim mcnamara! You are always the one to answer my queries! Thanks so much, really appreciate your help for taking time off to explain to me.