Thread synchronization

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am

Thread synchronization

Post by rubenswerk »

Hello,

I have one thread which is responsible for serving SD card operation. My idea is to trigger this thread by several other threads, which want to access SD card (I have no concurrent access to the card, only a single thread will request the FAT operation, depending on the operating mode). I want to use a SD card thread instead of a simple function call because the FAT functions consume a lot of stack memory. If I use function calls, all threads calling the FAT functions need to have a big stack. With the SD server thread, only one big stack is needed. I hope you agree.

What is the typical OS method to achieve this? I could create two events: The first to send a trigger signal from the 'main' thread to the 'SD card' thread, and a second event from the SD thread to the main thread as a response as soon as the operation is finished.
Is there an easier way to do this - a function that activates another thread and returns as soon as the other thread goes to sleep?

Or is it ok to use events for that type of synchronization?
Thanks, RuWe
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Thread synchronization

Post by Giovanni »

Messages if you want synchronous operations (send message and wait for answer), if you are OK with an asynchronous mechanism them mailboxes would be better (fire and forget, immediate return).

Note that a FatFs wrapper using messages has already been written, do a search in the forum.

Giovanni
rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am

Re: Thread synchronization

Post by rubenswerk »

Found it, thanks.
viewtopic.php?f=8&t=466
I'll have a close look at it.

Yes, synchronous operation would be fine for my use case.
Post Reply