Threads - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Threads

Description:

Threads & LWP Structure. Threads. LWPs. Threads library. Kernel - OS Scheduler. LWPs are managed by the OS scheduler. Threads library operations: ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 5
Provided by: shan80
Category:
Tags: os | threads

less

Transcript and Presenter's Notes

Title: Threads


1
Threads LWP Structure
Threads
Threads library
LWPs
Kernel - OS Scheduler
2
  • LWPs are managed by the OS scheduler.
  • Threads library operations
  • Manages the size of the LWP pool.
  • thr_setconcurrency(poolSize).
  • thr_getconcurrency().
  • Constructs new threads.
  • thr_create(stack,stackSize,func,arg,attributes,t
    id).
  • Attaches threads and LWPs by the following rules
  • A thread runs until it is suspended, or a thread
    with higher priority is created, then it frees
    the LWP.
  • Once a LWP becomes free a thread with highest
    priority is attached to it.

3
Time Quantum for Threads
  • Problem the threads library does not include
    timed threads.
  • Solution a counter thread
  • When the user wants to run a thread, a new thread
    is created with attributes - THR_BOUND (bound to
    a LWP until it exits).
  • The counter is busy waiting for the time the
    original thread is supposed to be running, and
    then suspends it.

4
context switch
context switch
context switch
LWP1
Scheduler
Scheduler
Thread A
Thread B
Time
LWP2
Free
Timer1
Free
Timer2
Notes Context switch is not done at the same
time for the two LWPs - the Scheduler first
initializes the new timer and only then
continues the thread, the timer first
suspends the thread and only then exits, but
the Scheduler waits for the timer to exit
before it continues. Size of LWP pool is always
2. The counter checks if the thread is blocked
all the time, and if so - returns the time left
for the thread to run and exits. This timing
method does not insures that the thread will run
the appropriate time - it relies on the fairness
of the OS Scheduler to run both LWPs fairly.
Write a Comment
User Comments (0)
About PowerShow.com