LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

multithread related problem for Win98/Win2K

Hi,
Our team had developed a test program using multithread strategy to test
two UUT.
The structure is as followed:
Each UUT test own two thread
-one is testing and control instrument,
-the other is to do limit check and update the UI
To change the global variable "index" to trig different UUT for test
- index=0 for UUT1
- index=1 for UUT2
The main example code is as followed:
int index;
HANDLE htest1, htest2, hlimit1, hlimit2, hstart, start_id, hstart1,
start1_id;
DWORD test1_id, test2_id, limit1_id, limit2_id;
int ready[2], fail_flag[2], abort_flag[2], rule[2], condition[2];
Main_test(void)
{
index=0;
do
{
enter=1;
// trigged by the external input
.
.
.

if(index==0)
{
htest1=CreateThread(NULL,0,((LPTHREAD_START_ROUTINE)Test1,
NULL, 0, &test1_id)
hlimit1=CreateThread(NULL,0,((LPTHREAD_START_ROUTINE)Limit1,
NULL, 0, &lmiit1_id);
}
else
{
htest2=CreateThread(NULL,0,((LPTHREAD_START_ROUTINE)Test2,
NULL, 0, &test2_id)
hlimit2=CreateThread(NULL,0,((LPTHREAD_START_ROUTINE)Limit2,
NULL, 0, &lmiit2_id);
}
enter=0;
} while(enter);
}
void Test1(void)
{

// using ready[0], fail_flag[0], abort_flag[0], rule[0] to
control
.
.
.
do
{
.
.
.
Sleep(20);
.
.
.
.
} while(condition[0]);
hstart=CreateThread(NULL,0,
((LPTHREAD_START_ROUTINE)Main_test, NULL, 0, &start_id)

ExitThread(test1_id);
ExitThread(limit1_id);
}
void Limit1(void)
{
.
.
.
Sleep(20);
.
.
.
}
void Test2(void)
{
// using ready[1], fail_flag[1], abort_flag[1], rule[1] to
control
.
.
.
do
{
.
.
.
Sleep(20);
.
.
.
.
} while(condition[1]);
hstart1=CreateThread(NULL,0,
((LPTHREAD_START_ROUTINE)Main_test, NULL, 0, &start1_id)
ExitThread(test2_id);
ExitThread(limit2_id);
}
void Limit2(void)
{
.
.
.
Sleep(20);
.
.
.
}
The application seems to be more stable under the Win2K, but not in
the Win98.
If you have any suggestion, please tell me detail. Thanks a lot.
Best regards,
Lambert
0 Kudos
Message 1 of 2
(2,494 Views)
Hi

Have you tried the "volatile" keyword for every variable, that is accesed from diferent threads?

Stephan
0 Kudos
Message 2 of 2
(2,494 Views)