Chapter 4 Operating Sys Flashcards
What is a thread?
- Each execution path within a process is called a
thread. - Every process has at least one thread of
execution
Process vs. Threads
Threads are the entities within a process
scheduled for execution on the CPU.
Every process has exactly one
program and every running program has at
least one thread of execution.
True or False:
- Every process must have 1 or more programs.
- A process may only have 1 thread of execution.
- A thread may contain multiple programs.
- If one thread blocks, a process may continue
running other threads in its program
What is multithreaded?
Multithreaded processes are executed similarly to
multiprogramming of processes: the CPU is switched rapidly among the threads creating the illusion of parallel execution.
Possible Thread Transition?
- Thread blocks for input
- Scheduler picks another thread
- Scheduler picks this thread
- Thread becomes able to run
again
pthread_create()
A new thread is created using the POSIX
pthread_create() call. The call to create specifies
the name of the procedure for the new thread to
run.
pthread_exit()
When a thread has finished the work it has been
assigned, it can terminate by calling
pthread_exit(). This call stops the thread and
releases its stack.
pthread_join()
Often a thread needs to wait for another thread
to finish its work and exit before continuing. The
thread that is waiting calls pthread_join() to wait
for a specific other thread to terminate.
pthread_yield()
If a thread wishes to relinquish its CPU time to allow
another thread to run, it can call pthread_yield().
No similar mechanism exists for processes. It is
assumed that processes “compete” for CPU time.
Threads, on the other hand, work in cooperation
with each other within a specific process. Therefore,
relinquishing the CPU to a sibling thread may be
advantageous to the process as a whole.