Which one you will use to implement critical section?

Answers were Sorted based on User's Feedback



Which one you will use to implement critical section?..

Answer / nirmalraj

Critical Section comes in single process environment they
didn't share accross process boundary.

In C if you wish to implement criticalsection you have to
use windows datastructure CRITICAL_SECTION and create a
object to access its members.

Initialize it
InitializeCriticalSection(&cs);
------------
-----------
function to call();
------------
DeleteCriticalSection(&cs);
.
.
call()
{
}

Is This Answer Correct ?    1 Yes 0 No

Which one you will use to implement critical section?..

Answer / svinto

Now sure what is asked but anyway:
1. If the question is how would you implement critical
section mechanism then the answer is to use a mutex.
2. If the question is to show how to use the critical
section then the following code fragment adresses that:
//
// Global variable or a member of some
// dynamically allocated structure, usualy within
// the data access to which it is protecting.
//
CRITICAL_SECTION cs;

VOID Init(VOID) {
InitializeCriticalSection( &cs );
}

VOID SomeCall(VOID) {
EnterCriticalSection( &cs );
//
// Thread-safe block of code protected by critical
section.
//
LeaveCriticalSection( &cs );
}

VOID
UnInit(VOID) {
DeleteCriticalSection( &cs );
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Windows Threads Interview Questions

Which one is not needed for Multi-program enviornment? 1) virtual memory 2) security 3) time sharing 4) none of the above.

7 Answers   Siemens,


Explain which protocol is working behind dhcp server? And what exactly dora does?

1 Answers  


What's difference between thread and process?

1 Answers  


How to update value using threads. Write code?

1 Answers  


explain readers-writers problem?

1 Answers  


What are multithreading models?

1 Answers  


What are the benefits of multithreaded programming?

1 Answers  


What are types of threads?

1 Answers  


Explain how scheduling and priority works in threads?

1 Answers  


What is thread injection?

1 Answers  


Can you explain too many times when I click on a sentence a caption comes on grr a pop up blocker maybe blockiing--however I have pushed the turn off pop upblocker. This only happens on google it does not happen on att.net?

1 Answers  


Which protocol is working behind DHCP server? and what excatly DORA does?

8 Answers   Wipro,


Categories