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: TextLCD mbed-rtos mbed
Fork of rtos_semaphore by
Revision 4:88b20795ea60, committed 2015-09-22
- Comitter:
- timtianyang
- Date:
- Tue Sep 22 04:43:11 2015 +0000
- Parent:
- 3:02e47d35a686
- Child:
- 5:8d6be7bf7f47
- Commit message:
- init upload
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Sep 22 04:43:11 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#3a05879a6c08
--- a/main.cpp Tue Jun 04 16:05:26 2013 +0100
+++ b/main.cpp Tue Sep 22 04:43:11 2015 +0000
@@ -1,20 +1,86 @@
+// Hello World! for the TextLCD
+
#include "mbed.h"
+#include "Display.h"
#include "rtos.h"
-Semaphore two_slots(2);
+#define N 5
+#define LEFT (i+N-1)%N
+#define RIGHT (i+1)%N
+#define THINKING 0
+#define HUNGRY 0
+#define EATING 2
+int state[N];
+Semaphore mutex(1);
+Semaphore* s[N];
+
+void take_forks(int i);
+void philosopher_thread(void const* arg);
+void put_forks(int i);
+void test(int i);
-void test_thread(void const *name) {
- while (true) {
- two_slots.wait();
- printf("%s\n\r", (const char*)name);
- Thread::wait(1000);
- two_slots.release();
+void eat(){
+ srand(time(NULL));
+ int r = rand()%3+2;
+ Thread::wait(r*1000);
+}
+void think(){
+ srand(time(NULL));
+ int r = rand()%3+3;
+ Thread::wait(r*1000);
+}
+
+void philosopher_thread(void const* arg){
+ int i=*((int *)arg);
+ while(1){
+ think();
+ take_forks(i);
+ eat();
+ put_forks(i);
}
}
-int main (void) {
- Thread t2(test_thread, (void *)"Th 2");
- Thread t3(test_thread, (void *)"Th 3");
+void take_forks(int i){
+
+}
+void put_forks(int i){
+
+}
+void test(int i){
+
+}
+int main() {
+
+ Display lcd;
+ for(int i=0;i<N;i++){
+ s[i]= new Semaphore(0);
+ }
+
- test_thread((void *)"Th 1");
+ int a=1;
+ int b=2;
+ int c=3;
+ int d=4;
+ int e=5;
+
+ Thread t1(philosopher_thread, (void *)&a);
+ Thread t2(philosopher_thread, (void *)&b);
+ Thread t3(philosopher_thread, (void *)&c);
+ Thread t4(philosopher_thread, (void *)&d);
+ Thread t5(philosopher_thread, (void *)&e);
+
+
+
+ int i=0;
+ while(1){
+ lcd.LCDEat(i);
+ if(i>0){
+ lcd.LCDDoneEating(i-1);
+ }
+ else{lcd.LCDDoneEating(4);}
+ i++;
+ if(i==5){i=0;}
+ wait(1);
+ }
+
}
--- a/mbed-rtos.lib Tue Jun 04 16:05:26 2013 +0100 +++ b/mbed-rtos.lib Tue Sep 22 04:43:11 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/ \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed-rtos/#9d001ed5feec
--- a/mbed.bld Tue Jun 04 16:05:26 2013 +0100 +++ b/mbed.bld Tue Sep 22 04:43:11 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file
