This post reviews yesterday, Wednesday August 19th 2020. Should I change the title to yesterday’s date or keep today’s date? Not sure, but I should probably stay consistent in my posts moving forward.
Although I’m physically exhausted and tired than usual from waking up early (around 04:30 to 05:00) every day to crank out studying or homework assignments, I feel emotionally and mentally better, less stressed out, knowing that I’m making forward progress on my assignments instead of dealing with an avalanche of work over the weekend.
Photo of the day
Breakfast on the hotel floor (Suncadia Hotel) with Elliott and Jess
Word of the Day
Despondent – in low spirits from loss of hope or courage.
The below write up consists of notes that I took while watching Multi-Threaded programming module from the Advanced Operating system’s refresher course1. I watched this third module before the second module (on File Systems, the next lecture series I’ll watch) because I started tackling the homework assignment that has us students debug a buggy multi-threaded program written with the POSIX threading library.
Although I was able to fix many of the problems by writing the man pages of various system calls (e.g. pthread_join2, pthread_exit3), I wanted to back my troubleshooting skills with some theoretical knowledge, and I’m glad I did because I had forgotten that if the main thread (first thread that spawns when OS starts the process) calls exit or return, then all threads exit; this behavior can be modified by having the main thread call pthread_join instead, causing the main thread to wait for some other specific thread to terminate.
Recap
Shows that Thread shares the heap, globals, constants, and code – but contains its own stack
Writing multi-threaded code is difficult and requires attention to detail. Nonetheless, multi-threaded offers parallelizing work — even on a single core. Threads are cheaper in terms of context switching when compare to process context switches, since threads share the same memory space (although each thread manages its own stack, which must be cleaned up after if the thread is created as a joinable thread — detached threads, on the other hand, are cleaned up automatically when they exit) When using threads, there are a couple different design patterns: team, dispatched, pipeline. Selecting the correct design depends on the application requirements. Finally, when writing multi-threaded programming, the program must keep in mind that there are two different problems that they need to consider: mutual exclusion and synchronization. Regardless, for the program to be semantically correct, the program must exhibit: concurrency, lack of deadlocks and mutual exclusion of shared resources/memory.
I divided studying into two sessions: one in the morning (around 04:30 am) and one in the evening after work and after my daughter has gone to bed. In the morning, I completed the administrative tasks and watched lectures that cover new material and in the evening I refreshed my memory by taking the operating systems review course.
OS Fundamentals Review: Quiz on calculating tag, index, and offset for cache entries