Question

True or False shared sem = Semaphore(0); Thread A: a1;sem.signal(); Thread B: sem.wait(); b1; Here, the...

True or False

shared sem = Semaphore(0);

Thread A: a1;sem.signal();

Thread B: sem.wait(); b1;

Here, the prefix shared indicates a shared variable.

When these two threads execute concurrently, event a1 will execute before event b1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Whichever thread starts first, thread B will always be calling sem.wait() as first statement. So, b1 can be executed only after thread A executes a1 and calls sem.signal(), then only thread B can continue.

So, It's TRUE

Add a comment
Know the answer?
Add Answer to:
True or False shared sem = Semaphore(0); Thread A: a1;sem.signal(); Thread B: sem.wait(); b1; Here, the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following two threads of a process, to be run concurrently in a shared memory...

    Consider the following two threads of a process, to be run concurrently in a shared memory (all variables are shared between the two threads): Assume the following: 1. a single-core system 2. load and store are atomic (i.e. they start and finish without interruption) 3. x is initialized to 0 before either thread starts, and 4. x must be loaded into a register before being incremented (and stored back to memory afterwards). The following questions consider the final value of...

  • Assume that we desire to have deadlock-free mutual exclusion using locks on a shared object implemented...

    Assume that we desire to have deadlock-free mutual exclusion using locks on a shared object implemented via a set of shared registers. Suppose we allow threads to go through the lock method without writing to any of the shared registers? In general, it will be impossible to tell if a thread is in the critical section by examining the shared object. It will result in deadlocks. Both (a) and (b) Neither (a) nor (b) Suppose a thread attempts to lock...

  • operating system engineering , please read the question and solve on the given skeleton code ....

    operating system engineering , please read the question and solve on the given skeleton code . Write a multi-threaded program with Semaphores as counters and pthread_mutex_t mutex to solve the producer-consumer problem: A bounded buffer is simply a global integer array of size N (2) which can be accessed by multiple threads. • Create two types of threads - Producer (2) and Consumer (2). Producers will write to the buffer, and the consumers will read the buffer. In this scenario,...

  • Enter True or False, depending on whether the corresponding statement is true or false. 1. If...

    Enter True or False, depending on whether the corresponding statement is true or false. 1. If the coefficient of correlation r = 0, then there is no linear relationship between the variable y and the variable x. 2. A straight line that slopes upward and exactly fits all data points would produce a correlation coefficient value of one. Consider the linear equation y = Bo + B1x. Enter your answers as a single letter indicating the correct answer, i.e. A...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • 6. Determine whether each of the following is true or false (note: the statement is true...

    6. Determine whether each of the following is true or false (note: the statement is true if it is always true, otherwise it is false). If you say it is true then refer to a known result or give a proof, while if you say it is false then give a counterexample, i.e., a particular case where it fails. (a) If A, B and C are independent, the Pr(AlBnc)- Pr (A) (b) The events S., A are independent (S is...

  • 8) (10 points) Determine if the following are true or false. If false, explain why or...

    8) (10 points) Determine if the following are true or false. If false, explain why or give an example to counter the false statement. a) Two events are disjoint if the occurrence of one does not affect the other. b) It is not possible to get a probability of exactly 0. c) Drawing without replacement is an example of dependent events. d) It is possible to have both a disjoint event and an independent event. e) The standard deviation of...

  • When events are mutually exclusive, P (A and B) = 0." True False

    When events are mutually exclusive, P (A and B) = 0." True False

  • How do I do this C++ in a Unix Environment assignment Given dot1m.c 1. The program (dot1m.c) uses...

    How do I do this C++ in a Unix Environment assignment Given dot1m.c 1. The program (dot1m.c) uses mutex to lock and unlock the shared resource (dotstr.sum) for access control as shown below. pthread_mutex_lock (&mutexsum); dotstr.sum += mysum; printf("Thread %ld did %d to %d: mysum=%f global sum=%f\n", offset,start,end,mysum,dotstr.sum); pthread_mutex_unlock (&mutexsum); 2. Modify dot1m.c program to use reader-writer lock (instead of mutex).      Replace the codes (for mutex) by the codes (for reader-writer lock).            To initialize reader-writer lock, pthread_rwlock_initializer.            At the end,...

  • True or False (a) If X ∩ Y = ∅ then the two events X and...

    True or False (a) If X ∩ Y = ∅ then the two events X and Y are independent? (b) If event X is independent of event Y, then X^c is independent of Y? (c) For a discrete random variable X, we have limx->∞ pX(x) = 0? (d) For a continuous random variable X, we have limx->∞ fX(x) = 0? (e) For a continuous random variable X, we have limx->0 fX(x) ≤ 1? (f) For two discrete random variables X...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT