cse threads review
admin
11月 13, 2020
0
Multithreads Benefits:
- Responsiveness
- Resource sharing
- Economy
- Scalability
Multicore systems putting pressure on programmers, chanllenges include
- Dividing activities
- Balence
- Data splitting
- Data dependency
- Testing and debugging
Three primary thread libraries
- POSIX Pthreads
- Win32 threads
- Java threads
Multithreading Models
- Many-to-One:
- Solaris Green Threads
- GUN Portable Threads
- One-to-One:
- Windows NT/XP/2000
- Linux
- Solaris 0 and later
- Many-to-Many:
- Windows NT/2000 with the ThreadFiber package
- Solaris prior to version 9
- Two-level Model:
Two primary ways of implementing Thread Libraries
- Library entirely in user space
- Kernel-level library supported by the OS
Compare Pthreads & Java threads
- Pthreads
- May be provided either as user-level or kernel-level
- A POSIX standard API for thread creation and synchronization
- API specifies behavior of the thread library, implementation is up to development of the library
- Common in UNIX operating systems
- Java Threads
- Java threads are managed by the JVM
- Typically implemented using the threads model provided by underlying OS
- Java threads may be created by
- Extending Thread class
- Implementing the Runnable interface
Threading Issues
- Semantics of fork() and exec() system calls
- Thread cancellation of target thread (Asynchronous or deferred)
- Signal handling (Synchronous and asynchronous)
- process signals:
- Signal is generated by particular event
- Signal is delivered to a process
- Signal is handled
- Options:
- Deliver the signal to the thread to which the signal applies
- Deliver the signal to every thread in the process
- Deliver the signal to certain threads in the process
- Assign a specific thread to receive all signals for the process
- Thread pools
- Advantages:
- Usually slightly after to service a request with an existing thread than create a new thread
- Allows the number of threads in the application be bound to the size of the pool
- Thread-specific data
- Allows each thread to have its own copy of data
- Useful when do not have control over the thread creation process(i.e when using a thread pool)
- Scheduler activations
- Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application
- Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library
- This communication allows an application to maintain the correct number kernel threads
Windows XP Threads
- one-to-one mapping, kernel-level
- Each thread contains
- A thread id
- Register set
- Separate user and kernel stacks
- Private data storage area
- context of the threads
- register set
- stacks
- private storage area
- primary data structures of a thread include
- ETHREAD (executive thread block)
- KTHREAD (kernel thread block)
- TEB (thread environment block)
Linux Threads
- Linux refers to them as tasks rather than threads
- Thread creation is done through clone() system call
- clone() allows a child task to share the address space of the parent task (process)
- struct task_struct points to process data structures (shared or unique)
Compare Linux Process and Thread
Process |
Thread(LWP) |
fork() |
clone() |
task_struct |
task_struct |
exec() |
join() |
exit()/abort() |
exit() |
近期评论