7 years, 10 months ago.

how to define the thread stack size ? mbed os 5.8.5.

when I create a thread, I code it:

#include "mbed.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Thread thread;
 
void led2_thread() {
    while (true) {
        led2 = !led2;
        wait(1);
    }
}
 
int main() {
    thread.start(led2_thread);
    
    while (true) {
        led1 = !led1;
        wait(0.5);
    }
}

now, how to define the thread stack size by myself?

1 Answer

7 years, 10 months ago.

Hi there,

You can specify the stack size of your Thread by changing the instantiation of your Thread object to the following:

Thread thread(priority, stack_size, stack_mem, name);

Where stack_size is the stack size (in bytes) requirements for the thread function (default: OS_STACK_SIZE). The other values and their type information can be viewed on the Thread class reference page here: https://os.mbed.com/docs/latest/reference/thread.html

Please let me know if you have any questions!

- Jenny, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!

Accepted Answer

Thank you for your reply. Now I can specify the stack and start it. I'd like to learn more about mbed os APIs.

posted by shang dong 12 Jun 2018

Hi again,

All of our API documentation can be viewed here: https://os.mbed.com/docs/latest/reference/apis.html For each API there are simple programs/examples utilizing the API. For example on the Thread API page, if you scroll to the bottom of the page there is a couple of small programs using the Thread API in different ways: https://os.mbed.com/docs/latest/reference/thread.html#thread-example

We also have a helpful Tutorials section within our documentation. Here's a tutorial with a few links describing how to use Mbed OS APIs: https://os.mbed.com/docs/latest/tutorials/using-apis.html

Please let me know if you have any questions!

- Jenny, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!

posted by Jenny Plunkett 12 Jun 2018