LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Does LabWindows/CVI have any function similar "DoEvents" in Virtual Basic?

Hi, all
Recently, I want to design a mulththreading testing program. I want to use "CreadThread" to build four threads. And to use the global variables to handshake the functionality of each thread. To avoid the halt of CPU or endless loop, there may have some method to release CPU. In VB, there have "DoEvents" function to release CPU. Does there have the similar function for LabWindows/CVI or in the Win32SDK ?
If there have the similar function, would you give me a sample program to check the functionality ?

Best regards,
Lambert Lin
0 Kudos
Message 1 of 4
(4,003 Views)
Lambert...

I believe the function you are after is Sleep(n).

int thread1 (void)
{
while (someCondition)
{
printf("Thread1");
Sleep(n);
}
}

int thread2 (void)
{
while (someOtherCondition)
{
printf("Thread2");
Sleep(n X 2);
}
}


The above should print out the following:

Thread1
Thread2
Thread1
Thread1
Thread2
Thread1
Thread1
Thread2

etc

The Sleep function can be found by searching the WinSDK. It puts the thread to sleep for a period of n units, and release control back to the other threads.

I hope this helps,

Chris
0 Kudos
Message 2 of 4
(4,003 Views)
If your app is multi-threading, DoEvents of VB is not a correct solution.
The DoEvents function of VB does not handle multi-threading issues
but just processes pending WM_ window messages that are
not processed yet.

If you are really looking for an equivalent to DoEvents, use the following
macro. If using C compiler, remove doubled-semicolons, which can only
be recognised by C++ compiler.

// DoEvents-equivalent operation
#define DOEVENTS \
{MSG __msg; \
while( ::PeekMessage( &__msg, 0, 0, 0, PM_REMOVE)) { \
::TranslateMessage( &__msg); \
::DispatchMessage( &__msg); \
} \
}

If you want to release CPU, use multithreading API functions such as
Sleep(), WaitForSingleObject() etc...

Makoto

"lambert" wrote in message
news:
5065000000080000000B400000-1012609683000@exchange.ni.com...
> Hi, all
> Recently, I want to design a mulththreading testing program. I want
> to use "CreadThread" to build four threads. And to use the global
> variables to handshake the functionality of each thread. To avoid the
> halt of CPU or endless loop, there may have some method to release
> CPU. In VB, there have "DoEvents" function to release CPU. Does there
> have the similar function for LabWindows/CVI or in the Win32SDK ?
> If there have the similar function, would you give me a sample
> program to check the functionality ?
>
> Best regards,
> Lambert Lin
0 Kudos
Message 3 of 4
(4,003 Views)
ProcessSystemEvents() will free the processor to process system events. It doesn't give you better control over multiple threads, but it lets the system resepond to other events (which may be from other applications).
Here's a section of the help for ProcessSystemEvents().
"While inside of a callback function or in code that does not call RunUserInterface() or GetUserEvent(), user interface and system events are not processed. If a particular function is overly time-consuming, it will essentially "lock-out" user interface and system events. To force these events to be processed, call ProcessSystemEvents() occasionally in the code that is locking out system events."
0 Kudos
Message 4 of 4
(4,003 Views)