00001
00002
00003
00004
00005
00006
00007
00008 #include <utility/ostream.h>
00009 #include <thread.h>
00010 #include <semaphore.h>
00011 #include <alarm.h>
00012 #include <display.h>
00013
00014 __USING_SYS
00015
00016 Thread * thred[5];
00017 Semaphore * semaphore;
00018
00019 OStream cout;
00020
00021 int test_function(int id)
00022 {
00023 cout << "[Thread=" << id << "] starting\n";
00024
00025 cout << "[Thread=" << id << "] will block in semaphore\n";
00026
00027 semaphore->p();
00028
00029 cout << "[Thread=" << id << "] released\n";
00030
00031 return(id);
00032 }
00033
00034 int main()
00035 {
00036 semaphore = new Semaphore(0);
00037
00038 for(int i = 0;i < 5;i++) new Thread(&test_function, i);
00039
00040 Alarm::delay(1000000);
00041
00042 cout << "Semaphore will be deleted\n";
00043
00044 delete semaphore;
00045
00046 cout << "The end!\n";
00047
00048 return 0;
00049 }