Interviewer And Interviewee Guide

Windows Threads Interview Question:

Which one you will use to implement critical section?

Submitted by: Administrator
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 );
}
Submitted by: Administrator

Read Online Windows Threads Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.