Page 1 of 1

Thread synchronization

Posted: Sun Aug 12, 2012 5:31 pm
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

Re: Thread synchronization

Posted: Sun Aug 12, 2012 5:43 pm
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

Re: Thread synchronization

Posted: Sun Aug 12, 2012 7:24 pm
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.