Terminating threads have to be wait ed on to avoid

This preview shows page 7 - 9 out of 16 pages.

Terminating threads have to be wait ed on to avoid turning them into zombies. If the main thread calls pthread exit the process is not terminated; the main thread goes to sleep and it is the job of the manager to wake it once the process terminates. In some situations threads need help to handle semaphore operations. The deallocation of thread-local data required iterating over all threads which had to be done by the manager. None of these problem necessarily implies that a manager thread has to be used. With some support in the kernel the manager thread is not necessary at all. With a correct implementation of the POSIX signal handling in the kernel the first item is solved. The second problem can be solved by letting the kernel perform the deallo- cation (whatever this actually might mean in an implementation). The third item can be solved by the kernel automatically reaping terminated threads. The other items also have solutions, either in the kernel or in the thread library. Not being forced to serialize important and frequently performed requests like cre- ating a thread can be a significant performance benefit. The manager thread can only run on one of the CPUs, so any synchronization done can cause serious scalability problems on SMP systems, and even worse scalability problems on NUMA systems. Frequent reliance on the manager thread also causes a significantly increased rate of context-switching. Having no manager thread in any case simplifies the design. The goal for the new implementation therefore should be to avoid a manager thread. 5.4 List of all Threads The old Linux threads implementation kept a list of all running threads which occa- sionally was traversed to perform operations on all threads. The most important use is to kill all threads when the process terminates. This can be avoided if the kernel takes care of killing of the threads if the process exist. The list was also used to implement the pthread key delete function. If a key is deleted by a call to pthread key delete and later reused when a following call 7
Image of page 7

Subscribe to view the full document.

Draft to pthread key create returns the same key, the implementation must make sure that the value associated with the key for all threads is NULL . The old implementation achieved this by actively clearing the slots of the thread-specific memory data structures at the time the key was deleted. This is not the only way to implement this. If a thread list (or walking it) has to be avoided it must be possible to determine whether a destructor has to be called or not. One way to implement this is by using generation counters. Each key for thread-local storage and the memory allocated for them in the thread’s data structures, have such a counter. When a key gets allocated the key’s generation counter is incremented and the new value is assigned to the counter in the thread data structure for the key. Deleting a key causes the generation counter of the key to be incremented again. If a thread exits only destructors for which the generation counter of the key matches the counter in the thread’s data structure are executed. The deletion of a key becomes a simple increment
Image of page 8
Image of page 9
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung
  • Native POSIX Thread Library, POSIX

{[ 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