8 years ago.

Using threads

As you can see in my previous question, mutexes are not working in my platform :( However, threads seem to be working... and I think I need to use them to implement the program I am building, so I am going to risk it and try to use threads without mutexes...

I would appreciate though some advice please on my problem

So far my program uses InterruptIn to activate some processing when a Touch Panel is touched. It is working great. However, when I touch a particular button I need to initiate a processing (make a series of motions with a stepper) If I do it there, it will lock the touch panel until it finishes so I guess I need to initiate a new thread. (I though of using tickers or timeouts.. but I dont know if they will work in this case).

So my question is how do you start (create) or stop (destroy) threads? (actually auto-destroy since the thread had to kill it self once it finishes its processing)

I read the API where the thread seems to be created in the constructor. In the example given in https://developer.mbed.org/handbook/RTOS the thread is created inside main().

How would you do for example if you want to create a thread only when you press the user button??? for example

InterruptIn button(p5);

void startThread() {
    // HERE START THREAD
}

int main()
{
button.rise(&startThread); 

while(1){
//something
    }
}

Should I use new or something like this?? And how can I make the thread kill it self??

Thank you so much for any help. I really need to complete this and I will appreciate your help

Be the first to answer this question.