Windows Threads Question:
Download Job Interview Questions and Answers PDF
Which one you will use to implement critical section?
Answer:
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 );
}
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 );
}
Download Windows Threads Interview Questions And Answers
PDF
Previous Question | Next Question |
Which one is not needed for Multi-program environment? | How to Kill a Particular Process in windows? |