The amount of time required to create the thread

This preview shows page 18 - 22 out of 24 pages.

" The amount of time required to create the thread prior to servicing the request. " If we allow all concurrent requests to be serviced in a new thread, unlimited threads could exhaust system resources. ! A better way to implement a server is to use a thread pool . Threads
Image of page 18

Subscribe to view the full document.

Threads 19 37 Threading Issues – Thread Pool (cont’d) ! A process creates a number of threads at process startup. ! The threads sit in a pool and wait for work. ! When a server receives a request, it awakens a thread from this pool – if one is available – and pass it the request to service. ! If the pool contains no available thread, the server waits until one becomes free. (usually line in a queue) ! Once the working thread completes its service, it returns to the pool and awaits more work. ! Advantages of thread pools: " Servicing a request with an existing thread is usually faster than waiting to create a thread. " Pools limit the number of thread. This is important on systems that cannot support a large number of concurrent threads. Threads 38 Threading Issues – Thread Pool (cont’d) ! The number of threads in the pool can be set heuristically. " For example, a pool can have 25 threads/CPU. ! Some thread-pool architectures can dynamically adjust the number of threads in the pool according to usage patterns. " Having a smaller pool when the load on the system is low – to save memory. Threads
Image of page 19
Threads 20 39 Threading Issues – Thread Pool (cont’d) ! The Win32 Thread Pool API provides several function related to thread pools. ! One such member is QueueUserWorkItem() function. QueueUserWorkItem(PoolFunction, NULL, 0); DWORD WINAPI PoolFunction(LPVOID Param) { /* this function runs as a separate thread */ } Threads 40 Threading Issues – thread specific data ! Threads belonging to a process share the data of the process. ! However … in some circumstance, each thread might need its own copy of certain data. " The data is called thread-specific data . ! Most thread libraries provide some form of support for thread- specific data. Threads
Image of page 20

Subscribe to view the full document.

Threads 21 41 Threading Issues – scheduler activation ! Some systems implementing the many- to-many model place an intermediate data structure between the user and kernel threads. " Lightweight process (or LWP, virtual processor) . ! The kernel provides an application with a set of virtual processors. ! Each LWP is attached to a kernel thread, and is scheduled by the operating system to run on physical processors. ! To the user-thread library, a LWP can be used to schedule a user thread (to run) . Threads 42 Threading Issues – scheduler activation (cont’d) ! When a user thread is blocked (performing I/O) , the kernel must notify the library to assign other user threads for running. ! Scheduler activation – a scheme for communication between the kernel and the thread library.
Image of page 21
Image of page 22
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung
  • System Call, Native POSIX Thread Library, thread libraries

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern