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
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 |
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 |
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 |
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 |
List the types of polymorphism in c++?
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?
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; }
By using c++ with an example describe linked list?
Write about the scope resolution operator?
Explain terminate() and unexpected() function?
How much is c++ certification?
How to reduce a final size of executable?
What is the difference between multiple and multilevel inheritance in c++?
What is the difference between static link library and dynamic link library?
How the delete operator differs from the delete[]operator?