11 years, 7 months ago.

Wait for signal in main thread?

Hello,

as I understand main() is already a running thread. So it must be possible to use Thread::signal_wait(0x1) and send this signal from another running thread?

It only works the other way round for me - because it gives an error if I write: main.signal_set(0x1);

Thanks,

Michael

1 Answer

11 years, 3 months ago.

Possibly this is what you are trying to achieve. I can't see how to do it with the signal_set and signal_wait methods. Incedently, does anyone know what the signal (0x1) is? Can other signal values be used and if so are they separate or can you use a mask to set, or more likely, wait on different signals simultaneously? I can't find any real documentation on how these should be used.

Cheers David.

main.cpp

#include "mbed.h"
#include "rtos.h"

DigitalOut led(LED1);
osThreadId mainThreadID;

void signal_thread(void const *argument) {
    while (true) {
        Thread::wait(1000);
        osSignalSet(mainThreadID, 0x1);
    }
}

int main (void) {
    mainThreadID = osThreadGetId();
    Thread thread(signal_thread);
    
    while (true) {
        // Signal flags that are reported as event are automatically cleared.
        osSignalWait(0x1, osWaitForever);
        led = !led;
    }
}