Tuesday, July 25, 2023

CST 334 - Week 5 Concurrency

 Throughout my time during this week I learned quite a few things, I will just mention some here below:

-I learned about the concept of concurrency and was introduced to the notion of threads as an abstraction for a single running process. Threads share the same address space, enabling them to access the same data. The state of a thread is similar to that of a process, with its own program counter and private set of registers. 

-There are a few reasons why we use threads. According to OSTEP text, it's for parallelism and avoiding blocking program program progress due to slow I/O. Threads enable multiple computations to be performed concurrently on multiple CPUs and allow for overlap of I/O with other activities in a program. 

-In order to prevent a race condition and therefore indeterminate outcomes, the concepts of critical sections, mutual exclusion, and atomicity are presented to address these challenges.

-I also learned about the pthreads library(POSIX threads). In order to write a multi-threaded program, you need to create threads. The pthread_create() function is used to create threads. This takes four arguments: thread, attr, start_routine, and arg. 

-To wait for a thread to complete, you use the pthread_join() function. 

-To make sure sections of code are mutually exclusive, you use locks. The pthread_mutex_lock() and pthread_mutex_unlock functions are used to acquire and release locks. When you properly initialize the locks, you can avoid issues.

-Condition Variables: These allow threads to signal and wait for events. The pthread_cond_wait() function puts a thread to sleep, waiting for a condition to be met. The pthread_cond_signal() function signals the condition to wake up a waiting thread. 

There was so much more I learned this week, but I hope this shows a bit of what you can learn in concurrency! 

No comments:

Post a Comment

CST 462S - Service Learning

Overall, my experience working as a volunteer for NTS was great and I wouldn't have changed it any way! What went well?  I'd say ove...