You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

main.cpp 732B

1234567891011121314151617181920212223242526272829
  1. #include "mbed.h"
  2. #include "cmsis_os.h"
  3. osSemaphoreId two_slots;
  4. osSemaphoreDef(two_slots);
  5. void test_thread(void const *name) {
  6. while (true) {
  7. osSemaphoreWait(two_slots, osWaitForever);
  8. printf("%s\n\r", (const char*)name);
  9. osDelay(1000);
  10. osSemaphoreRelease(two_slots);
  11. }
  12. }
  13. void t2(void const *argument) {test_thread("Th 2");}
  14. osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
  15. void t3(void const *argument) {test_thread("Th 3");}
  16. osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
  17. int main (void) {
  18. two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2);
  19. osThreadCreate(osThread(t2), NULL);
  20. osThreadCreate(osThread(t3), NULL);
  21. test_thread((void *)"Th 1");
  22. }