Created
July 24, 2017 17:17
-
-
Save deepikabhavnani/dab15ad56d1dcf6da114fec1d415c615 to your computer and use it in GitHub Desktop.
Thread Exit Hook Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
static void on_thread_terminate(osThreadId_t id); | |
volatile int flag; | |
DigitalOut led1(LED2); | |
void blinky() { | |
while (flag) { | |
led1 = !led1; | |
wait(0.5); | |
} | |
} | |
void counter() { | |
int array[10]; | |
while (1) { | |
flag++; | |
array[flag%10] = flag; | |
} | |
} | |
void on_thread_terminate(osThreadId_t id) { | |
printf("Thread: 0x%x Stack Size: 0x%x Stack Space: 0x%x \n", | |
(uint32_t)id, osThreadGetStackSize(id), osThreadGetStackSpace(id)); | |
} | |
// main() runs in its own thread in the OS | |
int main() { | |
DigitalOut led2(LED2); | |
Thread t1, t2; | |
flag = 1; | |
t1.start(callback(counter)); | |
t1.attach_terminate_hook(on_thread_terminate); | |
t2.start(callback(blinky)); | |
t2.attach_terminate_hook(on_thread_terminate); | |
wait(2); | |
t1.terminate(); | |
printf("Flag Value = %d \n", flag); | |
wait(2); | |
flag = 0; | |
t2.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment