Help me! I can't use Thread of RTOS

I tried a RTOS Thread example on the MBED web site.

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
Thread thread;

void led2_thread()
{
    while (true) {
        led2 = !led2;
        ThisThread::sleep_for(1000);
    }
}

int main()
{
    thread.start(led2_thread);

    while (true) {
        led1 = !led1;
        ThisThread::sleep_for(500);
    }
}

But I got a compile error like below.

Error: Identifier “Thread” is undefined in “main.cpp”, Line: 5, Col: 2

I was set only importing mbed.h.

How can I use Thread?

When you create a new program make sure you select a Mbed OS template (something like mbed-os-blinky). The important thing is to have an -os- string in the template name. Otherwise it could happen that your program will be based on the deprecated Mbed 2, which does not include RTOS. Hence, no Thread class is available. You can make a quick check. If you have a mbed-os library in the program folder then you should be OK. But if there is mbed library in the project folder then you are building a Mbed 2 program.

Thanks to you, I’ve been on time.