Multithread problem (SetEvent), URGENT!!
Posted on 1998-11-01
My project consists of 2 parts:
a/ the main processing part (MPP), which handles 2 kinds of
b/ the wait part (WP), that waits and get the 2 kinds of
The mechanism is like this:
1) in main(), in main.c, which is the (MPP), create 2 events in order to distinguish the 2 kinds of messages, onfirmation and indication:
// 1st kinda message: CONF, confirmation
hEventWaitConf = CreateEvent(NULL,
// 2nd kinda message: IND, indication, inwhich, it contains
// several kinds of micro_message, that I have to choose.
hEventWaitInd = CreateEvent(NULL,
2) begin a thread to do the wait job, which is called, (WP)
_beginthread( WaitLoop, 0, NULL );
// where the wait loop is also in main.c, while the EventLoop() is
// in another file called event.c
void WaitLoop(void *dummy )
extern void EventLoop(void);
if ( glb_shutdown == 2 ) break;
/* _endthread given to terminate */
======= in event.c
if ( the_que == QueueEmpty )
if ( msg == CONF )
if ( msg == IND )
// the ProcessEvent() is to analyse // the micro_msg to see
// if this is the one I wnat.
if (micro_msg == the_wanted_msg)
} // else
3)and in my processing procedure, i have to wait for these IND or CONF arrives
b4 I proceed, so:
:// these process may or may not in main.c
My problem is:
the SetEvent(hEventWaitInd) don't always work!
soemtimes the WaitforSingleObject(hEventInd) cannot be set in the functions,
and sometimes, it was 'mysteriously' set <-- this may due to the fact
that, it was set the 1st time, and did not reset itself, so for the 2nd time
i wait for it, it was already set. (dunno why coz I when i create this event,
it set it as FAULSE)
Will it be the SetEvent() is placed in different functions in different files?
1 more thing, one I was in the main(), waiting the single object to be set,
the wait thread (WP) was also halted.
Very frustrated, pls help!!!!
Thanks in advance.