Session 18
Monday, October 13

Processes, Threads, Concurrency, and Synchronization

Whenever we begin to share data among concurrently running processes and/or threads we face potential synchronization issues.  Important terms to understand as we begin this topic are these:

Processes 

As we know already, a process is a program whose execution is underway, managed by the operating system.  In general, processes may not share any data with other processes.  However, they do share resources, such as hard drives, printers, and so forth.They can also be set up through system calls to share data, such as files, variable values, and so forth.  In Unix, processes that are forked from already running processes do not share any RAM data, but do automatically share files that were already open when the fork was done.

Threads 

As we also already know, threads are like processes, except that they share actual code with each other.  That is, threads that are started in the context of a process share the code and data of the process.  However, they must be managed to have their own register and stack context for proper starting, stopping, and restarting.

Concurrency 

"Concurrency" in a literal sense implies that two or more activities are occurring at the same time.  In operating system parlance, concurrency means that various processes and threads have at least the illusion that they are running at the same time, when, in fact, their execution may only be interleaved (so quickly that to the user the might as well be running at the same time) based on a small slice of time given to each process and/or thread.  On multi-core computers, some process and/or threads may actually be running simultaneously, but typically there would still be more active processes and threads than there are cores, so the simultaneity would still be illusory.

Synchronization 

Whether there is true parallelism going on or not as a result of the availability of multiple cores, concurrently running processes and threads will face issues of synchronization.  That is, there will be shared resources and data, the access to which must be carefully synchronized to ensure the integrity of the data.  Thus, synchronization is the biggest issue facing designers of operating systems and application programmers developing applications in which processes and/or threads share resources.

There are various synchronization problems that have been well studied.

Deadlock

This was discussed briefly, and then an assigment was given for students to read about and understand deadlock. Then students were to design a program and test a program that could result in deadlock, and then modify it so that it would not result in deadlock.

Starvation

This topic was introduced by way of a discussion of the Dining Philosophers problem.  Again, an assigment was given for students to read about and understand starvation. In the second part of the deadlock program they were to write, in which deadlock would not occur, a discussion was to be made about whether starvation could result.