What is a mutex and a critical section.Whats difference
between them?How do each of them work?

Answers were Sorted based on User's Feedback



What is a mutex and a critical section.Whats difference between them?How do each of them work?..

Answer / prasenjit roy

Mutex is a locking object ( like a flag ) for avoiding the
simultaneous use of a common resource. It is also used to
lock the critical section.

Ctitical Section :: is a block of code which should run
atomically ie. there should be no contact switching while
this block executes and once the block starts it should
finish without any interruption.

Is This Answer Correct ?    10 Yes 0 No

What is a mutex and a critical section.Whats difference between them?How do each of them work?..

Answer / achal ubbott

Above answers are correct.now I tell why?
1. Critical Section Object works faster because Critical
section is a user object and is specific to a process.
Where as a Mutex is a kernel object and so many
processes running over the kernel can lock or
unlock/release it. So it is a bit heavier than Critical
Section and thus slow.
2. When control enters the critical section the interrupts
(from various devices like FEC, UART etc. ) to the CPU core
are disabled

Is This Answer Correct ?    7 Yes 0 No

What is a mutex and a critical section.Whats difference between them?How do each of them work?..

Answer / edward

Both of them are synchronization objects .Critical section
used for snychronization of threads in a same
process.Mutexs used for sybchronizating a threads in diff
process

Is This Answer Correct ?    7 Yes 2 No

What is a mutex and a critical section.Whats difference between them?How do each of them work?..

Answer / vikas

Both of them are synchronization objects.
Critical sections are used for intraprocess synchronization
while mutexes are required for interprocess
synchronization. The latter is much heavier in terms of
resources consumed.

Vikas
http://www.cppquestions.com

Is This Answer Correct ?    7 Yes 3 No

Post New Answer

More C++ General Interview Questions

List the types of polymorphism in c++?

0 Answers  


Write a program to reverse a linked list?

8 Answers   Catalytic Software, Satyam,


Which bitwise operator is used to check whether a particular bit is on or off?

0 Answers  


Find out the bug in this code,because of that this code will not compile....... #include <iostream> #include <new> #include <cstring> using namespace std; class balance { double cur_bal; char name[80]; public: balance(double n, char *s) { cur_bal = n; strcpy(name, s); } ~balance() { cout << "Destructing "; cout << name << "\n"; } void set(double n, char *s) { cur_bal = n; strcpy(name, s); } void get_bal(double &n, char *s) { n = cur_bal; strcpy(s, name); } }; int main() { balance *p; char s[80]; double n; int i; try { p = new balance [3]; // allocate entire array } catch (bad_alloc xa) { cout << "Allocation Failure\n"; return 1; }

2 Answers   Impetus,


By using c++ with an example describe linked list?

0 Answers  






Write about the scope resolution operator?

0 Answers  


Explain terminate() and unexpected() function?

0 Answers  


How much is c++ certification?

0 Answers  


How to reduce a final size of executable?

3 Answers  


What is the difference between multiple and multilevel inheritance in c++?

0 Answers  


What is the difference between static link library and dynamic link library?

7 Answers   Tech Mahindra,


How the delete operator differs from the delete[]operator?

0 Answers  


Categories