/* * Task.cpp * * Created on: 30.11.2010 * Author: istsveise */ #include "Task.h" #include #include #include #include using namespace std; void* timer_main(void* task) { Task* t = (Task*) task; while(true) { usleep(t->T*1000); sem_post(&t->threadSem); } return NULL; } void* execute_main(void* task) { cout << "Start execution..." << endl; Task* t = (Task*) task; t->execute(); return NULL; } Task::Task(int t=1000) :T(t) { sem_init(&this->threadSem,0,0); pthread_t timerthread; pthread_t executethread; pthread_create(&timerthread,NULL,&timer_main,(void*) this); pthread_create(&executethread,NULL,&execute_main,(void*) this); } Task::~Task() { } void Task::waitForNextCycle() { sem_wait(&this->threadSem); }