Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 7 months ago.
Thread variables
Hi there. Maybe I missed it because it's late and I'm tired. Is there a way to create an RTOS Thread "variable" that can be used repeatedly? I'm writing a lighting controller sequence where the main loop takes input from a serial device - a value 0 through 8 - and runs a sequence based on the input. Some sequences need a thread to keep looping indefinitely until another sequence value is read from the serial device, where other sequences are finite - they have a start and a finish - and can run as a discrete function and don't need a thread. My main loop reads a serial value, and, based on that value, either calls a discrete function, or starts a thread to run a sequence until another serial code stops it. Something like this:
Thread modeThread( doNothingThread ); while (1) { // serial code received modeThread.terminate(); if ( serialCodeForDiscreteSequence ) runSequence; else Thread modeThread( someContinuingSequence ); }
I'm getting:
<<quote>>"modeThread": has already been declared in the current scope <</quote>>
(Actually, the code isn't 100% accurate, since the scopes are, in truth, different, but it's still illustrative).
I'd like something like:
Thread *threadPointer
so I could reuse the thread variable for any of a number of tasks to run, rather than create a specific thread for each possible sequence. Is this possible? Thanks!