Threads Flashcards
Kernel Thread
Created and scheduled by the three. Can run in parallel in a multi-processor system since it is scheduled by the kernel scheduler.
User Thread
Created and managed (scheduled) completely by the threading library it is using. This means that the single parent process has many threads that are scheduled by that same process.
Many-to-One
Many user level threads are mapped to a single kernel thread and the their management is done by the library.
One-to-One
Each user thread is mapped to a single kernel thread. Meaning the management is done by the kernel.
Many-to-Many
Many user threads are mapped to many kernel threads. Allows the OS to decide how many kernel threads are needed.
Threads in Linux
No concept of threads. Each thread is just a process that shares resources with other processes.
Pthreads
A POSIX standard API for creating and syncing os user and kernel level threads.
Thread cancellation - two methods
Async: Cancels the thread immediately. Causes issues like unfreed resources and corrupt data.
Deferred (sync): The thread periodically checks if it should stop, giving it the chance to do any necessary cleanup.
Thread Pool
Create in advance N threads and have them waiting in a ready pool. When a new task arrives, use one of the existing threads to take care of it. Faster than creating a new thread or each task.