Mistake on this page?
Report an issue in GitHub or email us

PlatformMutex

PlatformMutex class hierarchy

The PlarformMutex class provides mutex stub functions in the absence of RTOS. This class enables you to use driver/application code when the RTOS is not present.

PlatformMutex class reference

Public Member Functions
void lock ()
void unlock ()

PlatformMutex example

The code below demonstrates usage of PlatformMutex.

#include "mbed.h"

PlatformMutex stdio_mutex;
Thread t2;
Thread t3;
    
void notify(const char* name, int state) {
    stdio_mutex.lock();
    printf("%s: %d\n\r", name, state);
    stdio_mutex.unlock();
}

void test_thread(void const *args) {
    while (true) {
        notify((const char*)args, 0); wait(1);
        notify((const char*)args, 1); wait(1);
    }
}

int main() {
    t2.start(callback(test_thread, (void *)"Th 2"));
    t3.start(callback(test_thread, (void *)"Th 3"));

    test_thread((void *)"Th 1");
}

Mbed OS uses the PlatformMutex class instead of the RTOS mutex for all drivers. For example, please see AnalogIn, BusOut, SPI, Serial and I2C.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.