I am implementing a program that runs 4 threads.
Functions:
void* SOURCE_in(struct SOURCE_1*);
void* SOURCE_out(struct SOURCE*);
void* SINK_out(struct SINK_1*);
void* SINK_in(struct SINK*);
Functions allow communication between 4 blocks. Block 1 communicates with block 2. Block 2 shares information with the third block. Block 3 associates information with block 4.
My problem is in main.c
int main(int argc, char** argv){
extern int p, e_source, e_sink_1, l_sink, l_source_1, flag, ctr_source;
extern int ctr_source_1, ctr_sink, ctr_sink1;
SOURCE source;
SINK sink;
SOURCE_1 source_1;
SINK_1 sink_1;
HANDLE CHT[4];
p = 0;
e_source = flag = 0;
l_sink = e_sink_1 = l_source_1 = 1;
max = 5;
ctr_source = ctr_source_1 = ctr_sink = ctr_sink_1 = 0;
F *f1 = fifo_init(10);
F *f2 = fifo_init(10);
source.output_source = f1;
sink.input_sink = f1;
sink_1.output_sink = f2;
source_1.input_source = f2;
CHT[0] = (HANDLE)_beginthread((void (*)(void *))&SOURCE_out, 0, &f1);
CHT[1] = (HANDLE)_beginthread((void (*)(void *))&SINK_in, 0, &f1);
CHT[2] = (HANDLE)_beginthread((void (*)(void *))&SINK_out, 0, &f2);
CHT[3] = (HANDLE)_beginthread((void (*)(void *))&SOURCE_in, 0, &f2);
WaitForSingleObject(CHT[0], INFINITE);
WaitForSingleObject(CHT[1], INFINITE);
WaitForSingleObject(CHT[2], INFINITE);
WaitForSingleObject(CHT[3], INFINITE);
getchar();
return 0;}
I read that the WaitForSingleObject function does not work with _beginthread .... But my functions are not of type nunsigned __stdcall ...
I create a program with errors, and I use breakpoints to test it, and everything was fine. when I compile, I have this problem:
"Win32 Thread" (0x11ec) 0 (0x0).
"Win32 Thread" (0x918) 0 (0x0).
"Win32 Thread" (0x8a4) 0 (0x0).
"Win32 Thread" (0x2a8) -1073741510 (0xc000013a).
"Win32 Thread" (0x12f8) -1073741510 (0xc000013a).
"[3984] SW = SW.exe: Native" -1073741510 (0xc000013a).
getchar()
, , - - . .
WaitForSingleObject, , .
, , .
, , .