Topics Covered in Lecture
1.0 Explain the benefits of concurrent programming
- The advantages of concurrent computing include:
- Increased program throughput—parallel execution of a concurrent program allows the number of tasks completed in a given time to increase proportionally to the number of processors according to Gustafson's law.
- High responsiveness for input/output—input/output-intensive programs mostly wait for input or output operations to complete. Concurrent programming allows the time that would be spent waiting to be used for another task.
- More appropriate program structure—some problems and problem domains are well-suited to representation as concurrent tasks or processes.
1.1 Create a simple pthreads program

1.2 List the main functions in the C pthreads API POSIX
- The POSIX thread libraries are a standards based thread API for C/C++.
It allows one to spawn a new concurrent process flow. It is most effective
on multi-processor or multi-core systems where the process flow can be scheduled to run on
another processor thus gaining speed through parallel or distributed processing.
Threads require less overhead than "forking" or spawning a new process because
the system does not initialize a new system virtual memory space and environment for
the process. While most effective on a multiprocessor system, gains are
also found on uniprocessor systems which exploit latency in I/O and other
system functions which may halt process execution. (One thread may execute
while another is waiting for I/O or some other system latency.)
Parallel programming technologies such as MPI and PVM are used in a distributed
computing environment while threads are limited to a single computer system.
All threads within a process share the same address space.
A thread is spawned by defining a function and it's arguments which will
be processed in the thread.
The purpose of using the POSIX thread library in your software is
to execute software faster.
1.3 Explain what the function parameters do. C
- Parameters − A parameter is like a placeholder. When a function
is invoked, you pass a value to the parameter. This value is referred to
as actual parameter or argument. The parameter list refers to the type,
order, and number of the parameters of a function. Parameters are
optional; that is, a function may contain no parameters.
1.4 Use these functions in a simple program
- See Lab5.
1.5 Explain why locks are used.
- Locks are used to prevent race conditions in threads running concurrently due to incorrect reads and writes on variables in critical sections of code.
1.6 Define race condition, mutual exclusion, and critical section
- Race condition occurs when programs try to access a variable at the same time thus increasing the chances of incorrectly reading and writing data into memory.
- Mutual exclusion is the practice that each thread running will access the variable one by one thus decreasing chances of error.
- Critical section of code is the part of the code where it is going to be updated thus being accessible by multiple threads.
1.7 Add pthread locks to C code to get mutual exclusion. Mutex
- The mutex object referenced by mutex shall be locked by calling pthread_mutex_lock(). If the mutex is already locked, the calling thread shall block until the mutex becomes available. This operation shall return with the mutex object referenced by mutex in the locked state with the calling thread as its owner.
1.8 Explain why special hardware instructions are often used for implementing locks.
- Hardware uses different methods like test and set to set the locks which is an all or nothing set of instructions.
1.9 Build thread-safe data structures using locks.
2.0 Explain performance issues when locks are added to data structures.
2.1 Explain why condition variables are used.
- Condition variables are used so that if a thread passes a certain condition, it can go on to execute another instruction. It is like an added layer of protection for threads when it is running.
2.2 Build a bounded buffer with condition variables.

No comments:
Post a Comment