• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

while loop?

I have a while loop that keeps looking for a flag to be set.. i.e.


//wait for flag to be set
while(!myClass->isFlagSet())
{
...........
}
//now that the flag is set, keep going...



But the problem is that during the while loop, nothing else is running, and the flag never gets set high.

This is in vxworks (for powerpc) (c++).

How can I get that flag to be updated during the while loop? Is there a better way to do that than with a while loop?
 
Well, somewhere you need to be updating that flag. Either a separate thread that is running, or inside the while loop call a function that performs whatever logic is needed to update the flag.

How you implement the other thread is up to, using a built in timing mechanism if your libraries have one or by creating a new thread explicitly to do the operations.

Perhaps if you gave more details about what you are trying to accomplish someone can come up with a better way.
 
Originally posted by: Crusty
Well, somewhere you need to be updating that flag. Either a separate thread that is running, or inside the while loop call a function that performs whatever logic is needed to update the flag.

How you implement the other thread is up to, using a built in timing mechanism if your libraries have one or by creating a new thread explicitly to do the operations.

Perhaps if you gave more details about what you are trying to accomplish someone can come up with a better way.

A message is being transmitted over ethernet to my application. When this message is received, I set the flag high. This message is transmitted periodically.

I clear the flag right before my while loop, and then use the while loop to make sure I have a fresh message before I continue. Unfortuneatly my application isn't windows based, so I can't use "DoEvents()" or something similar.
 
Whereever you are setting that flag needs to be setup to run in a seperate thread. Otherwise the loop will never end.
 
Does vxworks have pre-emptive multitasking or just cooperative?

Assuming the network code is working properly on both sides of the connection, it sounds like the event / message handler is never being allowed to run.

A message is being transmitted over ethernet to my application. When this message is received, I set the flag high. This message is transmitted periodically.

What is the event / message handler model for this? The fact that the packet is received in the TCP/IP stack doesn't do any good unless either:
(a) you are doing the read of it inside your while loop
(b) it is triggering an event / message handler function that preempts the function running the while loop.
(c) you're using multiple threads, with the network receive code in a separate thread from your while loop (as mentioned above)
 
How are you receiving your network messages? Ideally you'd want all your network communications to be handled in a separate thread that then notifies your other execution thread that there is something to process. Otherwise if your communications are handled by your main execution thread then when you are blocking the thread via your while loop you can not receive the network messages.
 
Yeah if there is no logic inside the loop to set the flag. There needs to be a separate thread running that sets it. You could have interrupts too, depending what your coding etc..
 
Back
Top