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.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 Semaphore s(5); // a pool of 5 chopsticks 00005 Timer mytime; 00006 00007 void notify(const char* name) { 00008 printf("%s acquired two chopsticks %8.1f\n\r", name,mytime.read()); 00009 } 00010 00011 void test_thread(void const* args) { 00012 while (true) { 00013 Thread::wait(1000+rand()%500); //Thinking 00014 s.wait(); 00015 s.wait(); 00016 notify((const char*)args); 00017 Thread::wait(500+rand()%500); //Eating 00018 s.release(); 00019 s.release(); 00020 } 00021 } 00022 00023 int main (void) { 00024 mytime.start(); 00025 Thread t2(test_thread, (void *)"Philosopher 2"); 00026 Thread t3(test_thread, (void *)"Philosopher 3"); 00027 Thread t4(test_thread, (void *)"Philosopher 4"); 00028 Thread t5(test_thread, (void *)"Philosopher 5"); 00029 test_thread((void *)"Philosopher 1"); 00030 }
Generated on Wed Sep 28 2022 06:18:19 by
1.7.2