Processes, Threads & Race Conditions

HW #4. Processes, Threads & Race Conditions   Assignment (60 points).  For this assignment you will create a group of threads and then try to coax them into producing as many race conditions as possible. First, your program should declare a single shared integer variable (i.e. a global variable) with initial value zero; then your program should spawn off the number of threads specified in the source file using the MAXTHREADS defined constant. We will use a for-loop to create these threads. We will designate threads created on even numbered iterations as adders and threads created on odd iterations as subtractors.   Adder Threads: (Adding threads WILL have their own thread function) Adder threads will execute the following steps: 1. Read global value and store it into temp 2. add 1 to the temp value 3. store temp value into global variable 4. print the following to the console: “Current Value written to Global Variables by thread : tid is  val” Were tid is the thread id and val is the value of the temporary variable AFTER adding 1 to it. 5. repeats steps 1 through 4 for MAXITERATIONS (this is a defined constant in the given source code).  Subtractor Threads: (Subtracting threads WILL have their own thread function) Subtractor threads will execute the following steps: 1. Read global value and store it into temp 2. subtract 1 from the temp value 3. store temp value into global variable 4. print the following to the console: “Current Value written to Global Variables by thread : tid is  val” Were tid is the thread id and val is the value of the temporary variable AFTER subtracting 1 from it. 5. repeats steps 1 through 4 for MAXITERATIONS (this is a defined constant in the given source code). Once all threads have finished, please print the value in main in the following way: “Final Value of Shared Variable : val” • Where val is the value stored in the shared variable. Since these threads are unsynchronized, there is a possibility of race conditions occurring, depending on the actual interleaved execution order of the various threads. Insert nanosleep() commands into your thread code to induce as many race conditions as possible by forcing an (in)appropriate interleaved execution sequence. A timespec struct has been given to you. You can change the values in the struct. The first value is the amount of time to sleep in seconds and the second value is the amount of time to sleep in nanoseconds. Modify these values to try to get the final value the furthest away from 0 zero as possible in either the negative or positive direction. As your program executes, it will produce a trace of output from

Hide 

Files: 415_HW4.pdf

Calculate the price of your order

Simple Order Process

Fill in the Order Form

Share all the assignment information. Including the instructions, provided reading materials, grading rubric, number of pages, the required formatting, deadline, and your academic level. Provide any information and announcements shared by the professor. Choose your preferred writer if you have one.

Get Your Order Assigned

Once we receive your order form, we will select the best writer from our pool of experts to fit your assignment.

Share More Data if Needed

You will receive a confirmation email when a writer has been assigned your task. The writer may contact you if they need any additional information or clarifications regarding your task

Let Our Essay Writer Do Their Job

Once you entrust us with your academic task, our skilled writers embark on creating your paper entirely from the ground up. Through rigorous research and unwavering commitment to your guidelines, our experts meticulously craft every aspect of your paper. Our process ensures that your essay is not only original but also aligned with your specific requirements, making certain that the final piece surpasses your expectations.

Quality Checks and Proofreading

Upon the completion of your paper, it undergoes a meticulous review by our dedicated Quality and Proofreading department. This crucial step ensures not only the originality of the content but also its alignment with the highest academic standards. Our seasoned experts conduct thorough checks, meticulously examining every facet of your paper, including grammar, structure, coherence, and proper citation. This comprehensive review process guarantees that the final product you receive not only meets our stringent quality benchmarks but also reflects your dedication to academic excellence.

Review and Download the Final Draft

If you find that any part of the paper does not meet the initial instructions, send it back to us with your feedback, and we will make the necessary adjustments.