00001 /* Glass - a distributed computing library 00002 Copyright (C) 2003-2009 Bruno Barberi Gnecco 00003 Copyright (C) 2009-2010 Corollarium Technologies 00004 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #ifndef _GLASS_THREAD_HH_ 00022 #define _GLASS_THREAD_HH_ 00023 00024 #include <boost/thread.hpp> 00025 00026 namespace libglass { 00027 00031 class GlassThread { 00032 public: 00033 GlassThread(bool autostart = false) { 00034 if (autostart) { 00035 this->start(); 00036 } 00037 } 00038 00039 void start() { 00040 t = boost::thread(&GlassThread::execute, this); 00041 } 00042 00043 virtual void execute() = 0; 00044 00045 virtual void cleanup() = 0; 00046 00047 void join() { 00048 t.join(); 00049 cleanup(); 00050 } 00051 00052 protected: 00053 boost::thread t; 00054 }; 00055 00056 } 00057 00058 #endif // _GLASS_SERIAL_HH_