00001 #include "mtasker.hh"
00002 #include <iostream>
00003
00004 using namespace std;
00005
00006 MTasker<> MT;
00007
00008 void menuHandler(void *p)
00009 {
00010 int num=(int)p;
00011 cout<<"Key handler for key "<<num<<" launched"<<endl;
00012
00013 MT.waitEvent(num);
00014 cout<<"Key "<<num<<" was pressed!"<<endl;
00015 }
00016
00017
00018 int main()
00019 {
00020 char line[10];
00021
00022 for(int i=0;i<10;++i)
00023 MT.makeThread(menuHandler,(void *)i);
00024
00025 int numWoken;
00026 for(;;) {
00027 while(MT.schedule());
00028 if(MT.noProcesses())
00029 break;
00030
00031 if(!fgets(line,9,stdin))
00032 break;
00033
00034 numWoken=MT.sendEvent(*line-'0');
00035 cout<<"Woke "<<numWoken<<" tasks"<<endl;
00036 }
00037 cout<<"No more tasks running"<<endl;
00038 }