Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that ses threads and synchronization. As a result, you will get

ID: 3528793 • Letter: W

Question

write a program that ses threads and synchronization. As a result, you will get experience in writing a program that actually runs in parallel on lenix using threads (pthreads) and synchronization. the program will create four threads. note that you will not be using fork and exec. Thread reader will read in each input line. if the line is longer than 63 characters, it will truncate it to 63 characters (plus the null byte at the end). just throw away (flust to end of line) any extra characters. you will read from stdin and write to stdout. thread writer will count the number of lines and print this number to stdout. you should develop a module that implements a queue of character string buffers. threads should terminate when there is no more input. do not use global variables to signal completion of the input for the various threads. makke sure to isolate the queue abstraction in a separate module. you should have functions for allocation, enqueuing and dequeuing. Each queue needs its own synchronization, which can be realized by semaphores.

Explanation / Answer

In order to satisfy the perpetual need for increased computing power, the hardware industry is steadily shifting toward multi- and many-core processor systems. Unlike the increased application performance attained by faster processors with higher clock speeds, performance improvements in many-core systems can only be achieved by writing efficient parallel programs. Forms of parallelism have existed in the software industry for a long time. However, creating mainstream software applications that harness the full power of parallel hardware requires significant changes from the practices designed for sequential applications. Testing parallel applications is not straightforward. For instance, concurrent bugs are difficult to detect due to the nondeterministic behavior exhibited by parallel applications. Even if these bugs are detected, it is difficult to reproduce them consistently. Further, after fixing a defect, it is difficult to ensure that the defect was truly rectified and not simply masked. In addition, parallelization can also introduce new performance bottlenecks that must be identified. In this article, we'll look at testing techniques for parallel programs and present six helpful tools you can use to locate potentially serious defects. We'll begin with the following categories of concurrency bugs: race conditions, incorrect mutual exclusions, and memory reordering. Race Conditions, Deadlocks, and More A race occurs when two or more threads of execution in a multi