My main thread sets up some other threads (starts them), and then needs to send them messages. The problem is, it tries to send the message too soon, and the threads haven't yet started.
Is it possible for a thread to block on a message send to a thread that hasn't started yet? Right now, I only know how to get the current thread,which means I don't even know the thread until it has entered its entry point, at which point i call chThdSelf() and store the result.
Is there a way to get the Thread* object from a thread's working area, and send it a message after having called chThdCreateStatic, but perhaps before the thread has begun executing, and just have that call block until the thread starts up and can receive the message?
TIA!
Any way to block a thread until another has started?
Moderators: RoccoMarco, lbednarz, tfAteba
Re: Any way to block a thread until another has started?
Oh! The create function returns the pointer to the thread! Now to see if it does the right thing.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Any way to block a thread until another has started?
Sending messages to a created thread is not an issue even if it hasn't reached the chMsgWait() yet, the sender would block and the receiver would then retrieve the message.
The start of a working area can be casted to a Thread but it is not recommended, the WA organization may change, better use the "official" thread reference released by the various chThdCreatexxx() functions.
Giovanni
The start of a working area can be casted to a Thread but it is not recommended, the WA organization may change, better use the "official" thread reference released by the various chThdCreatexxx() functions.
Giovanni
Re: Any way to block a thread until another has started?
Might be useful to provide a macro to give the Thread reference given a working area, but I don't need that now that I know I can get it from the create function.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Any way to block a thread until another has started?
The problem is that future implementation could also move the Thread structure out of the working area. This will be required, for example, when a memory protection mechanism will be implemented (using a MMU or MPU), in that case the stack would be thread-private and the Thread structure would be system-private. The safest approach is to use the returned pointer.
Giovanni
Giovanni
Re: Any way to block a thread until another has started?
Fair enough. It's all good. I was only asking at the time because that's all I thought I had. The returned pointer is perfect.