Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
Thread Class Reference
The Thread class allow defining, creating, and controlling thread functions in the system. More...
#include <Thread.h>
Public Types | |
| enum | State { Inactive, Ready, Running, WaitingDelay, WaitingInterval, WaitingOr, WaitingAnd, WaitingSemaphore, WaitingMailbox, WaitingMutex, Deleted } |
State of the Thread. More... | |
Public Member Functions | |
| Thread (osPriority priority=osPriorityNormal, uint32_t stack_size=DEFAULT_STACK_SIZE, unsigned char *stack_pointer=NULL) | |
| Allocate a new thread without starting execution. | |
| MBED_DEPRECATED_SINCE ("mbed-os-5.1","Thread-spawning constructors hide errors. ""Replaced by thread.start(task).") Thread(mbed | |
| Create a new thread, and start it executing the specified function. | |
| template<typename T > | |
| MBED_DEPRECATED_SINCE ("mbed-os-5.1","Thread-spawning constructors hide errors. ""Replaced by thread.start(callback(argument, task)).") Thread(T *argument | |
| Create a new thread, and start it executing the specified function. | |
| template<typename T , typename M > | |
| MBED_DEPRECATED_SINCE ("mbed-os-5.1","The start function does not support cv-qualifiers. ""Replaced by thread.start(callback(obj, method)).") osStatus start(T *obj | |
| Starts a thread executing the specified function. | |
| osStatus | join () |
| Wait for thread to terminate. | |
| osStatus | terminate () |
| Terminate execution of a thread and remove it from Active Threads. | |
| osStatus | set_priority (osPriority priority) |
| Set priority of an active thread. | |
| osPriority | get_priority () |
| Get priority of an active thread. | |
| int32_t | signal_set (int32_t signals) |
| Set the specified Signal Flags of an active thread. | |
| int32_t | signal_clr (int32_t signals) |
| Clears the specified Signal Flags of an active thread. | |
| State | get_state () |
| State of this Thread. | |
| uint32_t | stack_size () |
| Get the total stack memory size for this Thread. | |
| uint32_t | free_stack () |
| Get the currently unused stack memory for this Thread. | |
| uint32_t | used_stack () |
| Get the currently used stack memory for this Thread. | |
| uint32_t | max_stack () |
| Get the maximum stack memory usage to date for this Thread. | |
Static Public Member Functions | |
| static osEvent | signal_wait (int32_t signals, uint32_t millisec=osWaitForever) |
| Wait for one or more Signal Flags to become signaled for the current RUNNING thread. | |
| static osStatus | wait (uint32_t millisec) |
| Wait for a specified time period in millisec: | |
| static osStatus | yield () |
| Pass control to next thread that is in state READY. | |
| static osThreadId | gettid () |
| Get the thread id of the current running thread. | |
| static void | attach_idle_hook (void(*fptr)(void)) |
| Attach a function to be called by the RTOS idle task. | |
Detailed Description
The Thread class allow defining, creating, and controlling thread functions in the system.
Example:
#include "mbed.h" #include "rtos.h" Thread thread; DigitalOut led1(LED1); volatile bool running = true; // Blink function toggles the led in a long running loop void blink(DigitalOut *led) { while (running) { *led = !*led; Thread::wait(1000); } } // Spawns a thread to run blink for 5 seconds int main() { thread.start(led1, blink); Thread::wait(5000); running = false; thread.join(); }
Definition at line 62 of file Thread.h.
Member Enumeration Documentation
| enum State |
State of the Thread.
- Enumerator:
Constructor & Destructor Documentation
| Thread | ( | osPriority | priority = osPriorityNormal, |
| uint32_t | stack_size = DEFAULT_STACK_SIZE, |
||
| unsigned char * | stack_pointer = NULL |
||
| ) |
Allocate a new thread without starting execution.
- Parameters:
-
priority initial priority of the thread function. (default: osPriorityNormal). stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). stack_pointer pointer to the stack area to be used by this thread (default: NULL).
Member Function Documentation
| void attach_idle_hook | ( | void(*)(void) | fptr ) | [static] |
Attach a function to be called by the RTOS idle task.
- Parameters:
-
fptr pointer to the function to be called
Definition at line 335 of file Thread.cpp.
| uint32_t free_stack | ( | ) |
Get the currently unused stack memory for this Thread.
- Returns:
- the currently unused stack memory in bytes
Definition at line 222 of file Thread.cpp.
| osPriority get_priority | ( | ) |
Get priority of an active thread.
- Returns:
- current priority value of the thread function.
Definition at line 145 of file Thread.cpp.
| Thread::State get_state | ( | ) |
| osThreadId gettid | ( | ) | [static] |
Get the thread id of the current running thread.
- Returns:
- thread ID for reference by other functions or NULL in case of error.
Definition at line 331 of file Thread.cpp.
| osStatus join | ( | ) |
Wait for thread to terminate.
- Returns:
- status code that indicates the execution status of the function.
- Note:
- not callable from interrupt
Definition at line 117 of file Thread.cpp.
| uint32_t max_stack | ( | ) |
Get the maximum stack memory usage to date for this Thread.
- Returns:
- the maximum stack memory usage to date in bytes
Definition at line 284 of file Thread.cpp.
| MBED_DEPRECATED_SINCE | ( | "mbed-os-5.1" | , |
| "Thread-spawning constructors hide errors. ""Replaced by thread.start(task)." | |||
| ) |
Create a new thread, and start it executing the specified function.
- Parameters:
-
task function to be executed by this thread. argument pointer that is passed to the thread function as start argument. (default: NULL). priority initial priority of the thread function. (default: osPriorityNormal). stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). stack_pointer pointer to the stack area to be used by this thread (default: NULL).
Thread thread(priority, stack_size, stack_pointer); osStatus status = thread.start(task); if (status != osOK) { error("oh no!"); }
| MBED_DEPRECATED_SINCE | ( | "mbed-os-5.1" | , |
| "Thread-spawning constructors hide errors. ""Replaced by thread.start(callback(argument, task))." | |||
| ) |
Create a new thread, and start it executing the specified function.
- Parameters:
-
obj argument to task. method function to be executed by this thread. argument pointer that is passed to the thread function as start argument. (default: NULL). priority initial priority of the thread function. (default: osPriorityNormal). stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). stack_pointer pointer to the stack area to be used by this thread (default: NULL).
Thread thread(priority, stack_size, stack_pointer); osStatus status = thread.start(callback(argument, task)); if (status != osOK) { error("oh no!"); }
| MBED_DEPRECATED_SINCE | ( | "mbed-os-5.1" | , |
| "The start function does not support cv-qualifiers. ""Replaced by thread.start(callback(obj, method))." | |||
| ) |
Starts a thread executing the specified function.
- Parameters:
-
obj argument to task method function to be executed by this thread.
- Returns:
- status code that indicates the execution status of the function.
| osStatus set_priority | ( | osPriority | priority ) |
Set priority of an active thread.
- Parameters:
-
priority new priority value for the thread function.
- Returns:
- status code that indicates the execution status of the function.
Definition at line 135 of file Thread.cpp.
| int32_t signal_clr | ( | int32_t | signals ) |
Clears the specified Signal Flags of an active thread.
- Parameters:
-
signals specifies the signal flags of the thread that should be cleared.
- Returns:
- resultant signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
Definition at line 161 of file Thread.cpp.
| int32_t signal_set | ( | int32_t | signals ) |
Set the specified Signal Flags of an active thread.
- Parameters:
-
signals specifies the signal flags of the thread that should be set.
- Returns:
- previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
Definition at line 155 of file Thread.cpp.
| osEvent signal_wait | ( | int32_t | signals, |
| uint32_t | millisec = osWaitForever |
||
| ) | [static] |
Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
- Parameters:
-
signals wait until all specified signal flags set or 0 for any single signal flag. millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
- Returns:
- event flag information or error code.
- Note:
- not callable from interrupt
Definition at line 319 of file Thread.cpp.
| uint32_t stack_size | ( | ) |
Get the total stack memory size for this Thread.
- Returns:
- the total stack memory size in bytes
| osStatus terminate | ( | void | ) |
Terminate execution of a thread and remove it from Active Threads.
- Returns:
- status code that indicates the execution status of the function.
Definition at line 100 of file Thread.cpp.
| uint32_t used_stack | ( | ) |
Get the currently used stack memory for this Thread.
- Returns:
- the currently used stack memory in bytes
Definition at line 253 of file Thread.cpp.
| osStatus wait | ( | uint32_t | millisec ) | [static] |
Wait for a specified time period in millisec:
- Parameters:
-
millisec time delay value
- Returns:
- status code that indicates the execution status of the function.
- Note:
- not callable from interrupt
Definition at line 323 of file Thread.cpp.
| osStatus yield | ( | ) | [static] |
Pass control to next thread that is in state READY.
- Returns:
- status code that indicates the execution status of the function.
- Note:
- not callable from interrupt
Definition at line 327 of file Thread.cpp.
Generated on Tue Jul 12 2022 12:29:13 by
1.7.2
