Aricent Interview Question
Applications DevelopersCountry: India
In concurrent programming, a critical section is a piece of code that accesses a shared resource (data structure or device) that must not be concurrently accessed by more than one thread of execution. A critical section will usually terminate in fixed time, and a thread, task, or process will have to wait for a fixed time to enter it (aka bounded waiting). Some synchronization mechanism is required at the entry and exit of the critical section to ensure exclusive use, for example a semaphore.
mutex is short for mutual exclusion object. In computer programming, a mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously. When a program is started, a mutex is created with a unique name. After this stage, any thread that needs the resource must lock the mutex from other threads while it is using the resource. The mutex is set to unlock when the data is no longer needed or the routine is finished.
Yes, threads within the same process or within other processes can share mutexes.
Critical Section (at a given time one instance should process): Synchronize a piece of code or activities with in process or across processes in single application or multiple application.
Mutex(lock) : Locking mechanism which provides locks , this is used only when synchronization happens across processes in single application or multiple application, not within the current process. In Multiple application you need to have db for tracking.
Critical section is a segment of code which can be executed by one process at a time and other processes should wait at that time. Example is writing database or file, which are read by other processes or using a shared resourse.
- nav July 13, 2014MUTEX is a variable used as a token to execute the critical section.