3 years, 7 months ago.  This question has been closed. Reason: Off Topic

Multiple Mail Queues


So i'm still relatively new to Mbed os.

Is it possible to have multiple mail queues? Or for multiple threads to be able to read data from one mail queue?

I'm trying to read a some simple integer/float data from one thread, then have other threads display it/store it, but i'm struggling to find a safe way to be able to share data across multiple threads.

Thanks, Dan

A common way to share data between threads is to have a getter method that wraps access to the resource in a mutex lock. All access to the shared variable stays within the module that owns it so you can easily keep track of the mutex locks/unlocks. The C way to do this is make sure the module has a public (non-static function exposed in header file) getter method that other modules can call. The C++ way is to make your module a class with public getter (getter() of course wraps access to variable in mutex lock/unlock) and then probably pass the class into the Constructor of the object that needs it. If you inspect some of the mbed-os top level drivers you will see they use public getters with mutex wrappers.

posted by Graham S. 28 Dec 2017