Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this question, you are asked to create three threads and run them simultaneously. A, B and Threads that we will call C have blocks
In this question, you are asked to create three threads and run them simultaneously. A, B and Threads that we will call C have blocks of code that follow each other as follows:
- Thread A has three code blocks: A1, A2, A3 - Thread B has four code blocks: B1, B2, B3, B4 - Thread C has three code blocks: C1, C2, C3
What we call a code block actually consists of this piece of code:
a. By writing a main program, create 3 threads (A, B, C) in your program. Each thread is created by using the print function you wrote above (the function has its own data consisting of name and code block number A1, A2, A3, B1, etc.- as a parameter. by sending it) should show which code block it is currently running. Therefore, as can be understood from here, a code block for each thread tag five times in a row (A1A1A1A1A1 etc.). Code blocks are ordered sequentially in threads (A2 before A1 is finished). block will not start, etc.). without applying any synchronization control to your program. When you run it, you can observe that the code blocks of different threads are nested. need (like A1A1C1B1A1B1B1.....A3C2C3...).
b. Using semaphores, threads of the program you wrote above, in such a way sync so that every time you run your program: - Let C1 code block be run AFTER A1 code block. - Let code block A2 be run AFTER code block B1. - Let C2 code block be run AFTER B2 code block. - Let B3 code block be run AFTER A2 code block. - Let A3 code block be run AFTER C2 code block. - Let B4 be the LAST executed code block. It does not matter when and in what order the code blocks not mentioned above will run. there is none. You can program your program using the Linux semaphore library (#include). You can write. It is up to you to determine which functions from the library you should use. staying.
#include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started