Saturday, April 20, 2013
Explain the concepts of threads and processes in operating system?
Posted by
Sunflower
at
4/20/2013 08:29:00 PM
0
comments
Labels: Access, Attributes, Concept, Location, Memory, Multi-tasking, Multi-threading, Mutants, Mutual Exclusions, Operating System, Priority, Processes, Resources, Scheduling, Synchronize, Threads, Uses
|
| Subscribe by Email |
|
Saturday, January 9, 2010
Critical Regions
A critical region is a section of code that is always executed under mutual exclusion. Critical regions shift the responsibility for enforcing mutual exclusion from the programmer(where it resides when semaphores are used) to the compiler.
They consist of two parts:
- Variables that must be accessed under mutual exclusion.
- A new language statement that identifies a critical region in which the variables
are accessed.
var
v : shared T;
...
region v do
begin
...
end;
All critical regions that are ‘tagged’ with the same variable have compiler-enforced mutual exclusion so that only one of them can be executed at a time:
Process A:
region V1 do
begin
{Do some stuff.}
end;
region V2 do
begin
{Do more stuff.}
end;
Process B:
region V1 do
begin
{Do other stuff.}
end;
Here process A can be executing inside its V2 region while process Bis executing inside its V1 region, but if they both want to execute inside their respective V1 regions only one will be permitted to proceed.
Posted by
Sunflower
at
1/09/2010 12:09:00 AM
0
comments
Labels: Code, Critical Region, Mutual Exclusions, Programing, Semaphores
|
| Subscribe by Email |
|
Tuesday, August 25, 2009
Overview Of Mutual Exclusions in Operating Systems
A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing.
Formally, while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished executing the shared variable, one of the processes waiting; while that process has finished executing the shared variable, one of the processes waiting to do so should be allowed to proceed. In this fashion, each process executing the shared data (variables) excludes all others from doing so simultaneously. This is called Mutual Exclusion.
Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code where a process or thread accesses a common resource. The critical section by itself is not a mechanism or algorithm for mutual exclusion. A program, process, or thread can have critical section in it without any mechanism or algorithm, which implements mutual exclusion.
Examples of such resources are fine-grained flags, counters or queues, used to communicate between code that runs concurrently, such as an application and its interrupt handlers. The problem is acute because a thread can be stopped or started at any time.
How Mutual Exclusion is Done ?
We need to stop the two threads from working on the same data at the same time. The most common way to do this today is by using locks. A lock can be either locked or unlocked. As long as you do not forget to lock or unlock the door, this algorithms guarantees mutual exclusion and protects the so called critical region.
C:
1. omp_set_lock (&my_lock);
2. i++;
3. omp_unset_lock (&my_lock);
Actually, the lock needs to be initialized beforehand and destroyed sometime afterwards as well, but that's not too difficult either.
C:
1. #pragma omp critical
2. {
3. i++;
4. }
Or even simpler, like this:
C:
1. #pragma omp atomic
2. i++;
This basically does the same thing, except you do not need to worry about initialization and destruction of the lock and you cannot forget to unlock the mutex accidentally.
Posted by
Sunflower
at
8/25/2009 07:37:00 PM
0
comments
Labels: Algorithm, Deadlocks, Lock, Mutex, Mutual Exclusions, Unlock
|
| Subscribe by Email |
|