// Copyright 2005, The Tanoshi development team // Assigned to public domain, Use as you wish withou restriction. #include #include #include #include #include #include // hack :P Tanoshi::ReadWriteLock locker; class thread_proc : public Tanoshi::Thread { public: void run(); private: Tanoshi::Timer timera; Tanoshi::EventManager eventmanager; private_slots: void timera_slot(); }; void thread_proc::run() { printf("thread started... %d\n", Tanoshi::Thread::thisThreadId()); timera.timeout.connect(sigc::mem_fun(this, &thread_proc::timera_slot)); timera.setEventManager(&eventmanager); timera.setTimeOut(1); timera.setRunOnce(false); timera.start(); printf("timer started for thread proc...\n"); for(;;) { eventmanager.processEvent(); eventmanager.sleep(); } } void thread_proc::timera_slot() { locker.writeLock(); printf("running on thread process: %d\n", Tanoshi::Thread::thisThreadId()); locker.readWriteUnlock(); } class main_proc : public sigc::trackable { public: void run(); private: Tanoshi::Timer timera; Tanoshi::EventManager eventmanager; thread_proc threadedtest; private_slots: void timera_slot(); }; void main_proc::run() { threadedtest.start(); timera.timeout.connect(sigc::mem_fun(this, &main_proc::timera_slot)); timera.setEventManager(&eventmanager); timera.setTimeOut(3); timera.setRunOnce(false); timera.start(); printf("timer started for main proc...\n"); for(;;) { eventmanager.processEvent(); eventmanager.sleep(); } } void main_proc::timera_slot() { locker.writeLock(); printf("running on main process: %d\n", Tanoshi::Thread::thisThreadId()); locker.readWriteUnlock(); } int main() { main_proc maintest; maintest.run(); }