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?
Starting up/Resuming Threads
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Starting up/Resuming Threads
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
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
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.
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.
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Starting up/Resuming Threads
Hi,
The events timer is under /os/various.
There is chEvtGetAndClearEventsI(), it is not blocking.
About
The events timer is under /os/various.
There is chEvtGetAndClearEventsI(), it is not blocking.
About
Who is online
Users browsing this forum: No registered users and 12 guests