Main Page | Class Hierarchy | Class List | File List | Class Members

menu-example.cc

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()); // do everything we can do
00028     if(MT.noProcesses())  // exit if no processes are left
00029       break;
00030 
00031     if(!fgets(line,9,stdin)) // read a keypress
00032       break;
00033     
00034     numWoken=MT.sendEvent(*line-'0'); // wake up waiters
00035     cout<<"Woke "<<numWoken<<" tasks"<<endl;
00036   }
00037   cout<<"No more tasks running"<<endl;
00038 }

Generated on Sun Feb 8 12:07:52 2004 for MTasker by doxygen 1.3.5