In: Computer Science
Which of the following statements about sharing data by threads is (are) correct? Select all that apply.
(a) When kernel-mode threads in a process share data, a race condition will not occur, since threads are managed operating systems.
(b) When kernel-mode threads in a process share data, a race condition can occur and therefore, a semaphore (or semaphores) should be used to prevent race conditions.
(c) When user-mode threads in a process share data, a race condition will not occur, since the thread scheduler in each process manages (schedules) threads.
(d) When user-mode threads in a process share data, a race condition can occur and therefore, a semaphore (or semaphores) should be used to prevent race conditions.
(e) None of the above.
First of all, the second option (b) and fourth option (d) both are same.
The options (a) and (c) are wrong, because a race condition can or may always occur while threading. A race condition occurs inside a critical section. It happens as a result of difference in executing multiple threads inside a critical section to that of the order in which the thread executes. A critical section is one where the shared variables in a code can be accessed. nly one variable at a time can be accessed in critical section
So the correct option is (b). semaphores can be used to prevent race conditions. Semaphores signalling mechanism using wait and signal operation. Its a non negative variable. A thread that is waiting in it can be signalled by other threads.It uses wait and signal atomic operations for process synchronization. They are used for controlling the access of shared or common data by multiple processes.