Reputation: 145
I'm having trouble with very basic Windows programming, implementing a simple producer/consumer system.
My struct:
typedef struct FILE_BUFFER { //Circular buffer of max size BUF_SIZE
INT count; //buffer size
LPTSTR buf[BUF_SIZE]; //actual buffer of file names
BOOL stopRequested; //Exit flag
LPCRITICAL_SECTION lock; //Synch stuff
PCONDITION_VARIABLE notEmpty;
PCONDITION_VARIABLE notFull;
}FILE_BUFFER;
FILE_BUFFER fb;
my init function (ran in main thread)
VOID init() {
fb.stopRequested = FALSE;
fb.count = 0;
InitializeCriticalSection(fb.lock);
InitializeConditionVariable(fb.notEmpty);
InitializeConditionVariable(fb.notFull);
}
The init function cause exception to be thrown on the InitializeConditionVariable instruction, of type Access Violation (ntdll.dll).
I'm using Visual Studio 2017 and compiling for Windows x64
Thanks
Upvotes: 0
Views: 233
Reputation: 37600
You are passing uninitialized pointers as parameters to InitializeCriticalSection
and InitializeConditionVariable
. You should allocate appropriate structures and pass a pointer to them instead:
CRITICAL_SECTION lock; //Synch stuff
CONDITION_VARIABLE notEmpty;
CONDITION_VARIABLE notFull;
...
InitializeCriticalSection(&(fb.lock));
InitializeConditionVariable(&(fb.notEmpty));
InitializeConditionVariable(&(fb.notFull));
Upvotes: 4