CPSC 3220 - DAY 7 SEPTEMBER 19, 2017 ================================================================================ Threat threads as will be executed eventually. Threads must be designed to work with any schedule. thread_create(thread, func, args) -create a new thread to run function thread_yield() -relinquish processor voluntarily thread_join(thread) -in parent, wait for forked thread to exit, then return thread_exit(return_value) -quit thread and clean up, wake up joiner if any. Thread Context Switch Voluntary: -Thread_yield() -Thread_join() Involuntary: -Interrupt or exception -Other thread with higher priority Fork/Join Concurrency -Threads can create children, and wait for their completion -Data only shared before fork/after join -Otherwise, extra code to coordinate access -Examples: -Web server: fork new thread for each new connection -As long as the threads are completely independent -Merge sort -Parallel memory copy Threads at User and Kernel Level -Multiple single-threaded processes -System calls access shared kernel data structures -Multiple multi-threaded user processes -Each with multiple threads, sharing same data structures, isolated from other user processes -Kernel design -kernel can have zero threads (e.g., IBM MVT) -Kernel can use internal threads -in general, interrupt handlers are not threads can be used to wake or signal threads.