Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months ago.
Problems with mutex in Nucleo F091?
Hello. I am reading about these multithreading features and I find them interesting.
I am currently trying it using a STM32F091.
When I try the following code:
#include "mbed.h"
#include "rtos.h"
DigitalOut led1(LED1);
DigitalOut led2(PA_0);
DigitalIn mybutton(USER_BUTTON);
uint32_t mywait=500;
//Mutex stdio_mutex; //<===========HERE THE PROBLEM
void led2_thread(void const *args) {
while(true)
{
if (mybutton == 0) { // Button is pressed
led2 = !led2;
// stdio_mutex.lock();
mywait=mywait+100;
if(mywait>1000) mywait=100;
// stdio_mutex.unlock();
}
}
}
int main() {
Thread thread(led2_thread);
while (true) {
led1 = !led1;
Thread::wait(mywait);
}
}
However , in order to protect the variable mywait I am thinking of using mutex. However even the mere declaration of a mutex (not even using it!) produces that the program does not work anymore.
Can someone please help me with this??
Thanks a lot