Question about synchronization Consider the three threads shown below. Using pse
ID: 3800017 • Letter: Q
Question
Question about synchronization
Consider the three threads shown below. Using pseudo-code to show how it is possible to ensure that section a2 will run before section b2 and that section b2 will run before section c2. (I am thinking to use Binary Semaphores or Mutex to lock the critical section, could you please help me? There are two other solutions in Chegg, however, obviously they don't meet this requirement.)
Thread A Thread B Thread C
section a1 section b1 section c1
section a2 section b2 section c2
Explanation / Answer
Here assuming that the 3 threads are in a processor, So we need to schedule this accordingly using semaphores.
for this, we use a sequential type of allocation of a process to threads. Now assume that the Semaphore we are using be SEM.
For this, we are using a for loop to do this operation.
/*the following code is repeated every time the processor is ready to take next process */
schedulethreads(Type SEQ_ASG) {
if(SEQ_ASG == thread(A)) {
SEQ_ASG= thread(B);
}
elseif (SEQ_ASG==thread(B)) {
SEQ_ASG=thread(C);
}
else {
SEQ_ASG = thread(A);
}
}
/*this line of code is to assign the new process to the processor */
if(SEM==0) {
SEQ=schedulethreads(SEM_OLD);
SEM = SEQ;
}
SEM_OLD: keeps track of the thread that is done the processing.
here, you need to observe that Each thread is loaded according to the scheduling Mechanisms, which means all the processes are loaded in a sequential manner. The methods of scheduling like Shortest job first algorithm or first comes first served or round-robin algorithms.
every time the job is kept ready then the process is assigned to the thread.
The processor always does the job of threads in a sequential manner. this concludes the answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.