CST 334 - Module 5

 Week 5,

This module's subject involved a lot to do with using threads and dealing with concurrency. Having processes use threads to complete smaller portions of the process concurrently with other threads is a good way to complete tasks quickly. However, the main problem with using threads is making sure the outcome of the process is determinate, meaning you get the result you want every time. Sometimes without taking measures to keep the processes determinate, you can get an unexpected outcome. An example that the text we are reading brings to light is say you want to use a thread to increment a global variable 1 million times. So, if you want 2 threads to do this, you expect the outcome of the whole process to return 2 million. However, what you ended up getting was 1,984,865, not quite 2 million is it? This happens when two or more threads try and read/write a global variable (critical section) at the same time. Before one thread can change the global variable, another thread reads from the global variable before the change occurs, thus two threads just set the global variable to the same thing. To prevent this, we strive to achieve mutual exclusion with all the threads being used. We do this using what are called locks and conditions. So, if a thread has entered a critical section, it holds a lock which tells other processes to wait or sleep until the thread holding the critical section is done and releases the key and signals to the other threads that they can enter the critical section. There are many different ways to achieve this goal using these functions, but in short this is how you would be able to maintain concurrency using threads.

Comments

Popular posts from this blog

CST 300 - Module 4

CST 300 - Module 2

CST 300 - Module 3