00001 //--------------------------------------------------------------------------- 00002 // thread 00003 //--------------------------------------------------------------------------- 00004 #ifndef __THREAD_H 00005 #define __THREAD_H 00006 #include <pthread.h> 00007 #include <string> 00008 namespace System{ 00009 00011 template <class X> 00012 class Mutexed{ 00013 private: 00015 pthread_mutex_t mutex; 00017 X data; 00018 public: 00020 Mutexed(); 00022 Mutexed(X n); 00024 void operator=(X n); 00026 X operator*(); 00028 X get(); 00030 void lock(); 00032 void unlock(); 00033 }; 00034 00035 00037 class Thread{ 00038 protected: 00040 pthread_t id; 00041 public: 00043 virtual void* tmain(void* args)=0; 00045 void start(void* args); 00047 void wait4(); 00048 }; 00049 00050 template class Mutexed<int>; 00051 template class Mutexed<bool>; 00052 template class Mutexed<unsigned char*>; 00053 template class Mutexed<unsigned int>; 00054 template class Mutexed<char>; 00055 template class Mutexed<std::string>; 00056 00057 00058 } // end of namespace 00059 #endif // __THREAD_H