What is a thread?
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:
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?
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.