Page 1 of 1
Starting up/Resuming Threads
Posted: Thu Mar 05, 2020 2:13 pm
by JSStabl
I have a system where I have a bunch of threads that are running when i'm in steady state operation. However when the device is started I don't want them to be running, I would have an init thread that checks a bunch of things on periphery and then starts up the other tasks/threads. I also want to be able to stop all steady state threads and restart them at a later time.
Whats the best chibiOS paradigm to use here? Can I create threads without starting them and have the init thread start/stop them accordingly? Or do I use messages/mailboxes/events to have threads start/stop their processes themselves?
Re: Starting up/Resuming Threads
Posted: Thu Mar 05, 2020 2:52 pm
by Giovanni
Hi,
The best approach is to have the thread wait on something. It could be the same semaphore/event/mailbox they wait on for normal operations, if you stop sending events to them they stop running.
Short: don't trigger them and they wont run.
Note that in ChibiOS killing/stopping/changing-priority of OTHER threads is forbidden by choice, it is usually unsafe to do so.
Giovanni
Re: Starting up/Resuming Threads
Posted: Thu Mar 05, 2020 4:28 pm
by JSStabl
Understood.
Seems like a bunch overhead for my "init" thread though. Meaning I have to actively keep sending semaphores/events in order for the threads to keep running, that takes computing.
What I'm looking for is more of an enable/disable flag. Using a regular global boolean flag set by the init thread and checked by the consuming threads might work, but I'm unsure if that is to be considered safe or not.
Has the event_timer_t (from
http://www.chibios.com/forum/viewtopic.php?t=2752) been deprecated? Couldn't find it anywhere.
How about using:
http://www.chibios.org/dokuwiki/doku.ph ... tos:wakeup and an event for actually letting suspending the thread itself?
Start Thread suspended -> Resume Thread from Init -> Set ThreadStop Event -> Event suspends itself -> wake up using ThreadResume
The only issue here is that there are only blocking functions for events, no if checks.
Re: Starting up/Resuming Threads
Posted: Thu Mar 05, 2020 7:06 pm
by Giovanni
Hi,
The events timer is under /os/various.
There is chEvtGetAndClearEventsI(), it is not blocking.
About