Index: code/trunk/src/core/CMakeLists.txt
===================================================================
--- code/trunk/src/core/CMakeLists.txt	(revision 3301)
+++ code/trunk/src/core/CMakeLists.txt	(revision 3304)
@@ -61,4 +61,8 @@
   TclBind.cc
   TclThreadManager.cc
+  
+  # multithreading
+  Thread.cc
+  ThreadPool.cc
 )
 ADD_SUBDIRECTORY(input)
Index: code/trunk/src/core/Clock.cc
===================================================================
--- code/trunk/src/core/Clock.cc	(revision 3301)
+++ code/trunk/src/core/Clock.cc	(revision 3304)
@@ -59,5 +59,5 @@
         tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
 
-        if (timersTime > 0x7FFFFFF0)
+        if (timersTime > 0xFFFFFFFF/4)
         {
             // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
@@ -74,5 +74,5 @@
     unsigned long long Clock::getRealMicroseconds() const
     {
-        return this->timer_->getMicroseconds();
+        return this->timer_->getMicroseconds() + this->storedTime_;
     }
 }
Index: code/trunk/src/core/ConsoleCommand.h
===================================================================
--- code/trunk/src/core/ConsoleCommand.h	(revision 3301)
+++ code/trunk/src/core/ConsoleCommand.h	(revision 3304)
@@ -32,4 +32,6 @@
 #include "CorePrereqs.h"
 
+#include <boost/preprocessor/cat.hpp>
+
 #include "ArgumentCompletionFunctions.h"
 #include "CommandExecutor.h"
@@ -39,27 +41,25 @@
 
 #define SetConsoleCommand(classname, function, bCreateShortcut) \
-    SetConsoleCommandAliasMulti(classname, function, #function, 0, bCreateShortcut)
+    SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
-    SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut)
-#define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \
-    SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
+    SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)
 
-#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
-    orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
+#define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \
+    orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
 
 
 #define SetConsoleCommandShortcut(classname, function) \
-    SetConsoleCommandShortcutAliasMulti(classname, function, #function, 0)
+    SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
 #define SetConsoleCommandShortcutAlias(classname, function, name) \
-    SetConsoleCommandShortcutAliasMulti(classname, function, name, 0)
-#define SetConsoleCommandShortcutAliasMulti(classname, function, name, number) \
-    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
+    SetConsoleCommandShortcutAliasGeneric(classname, function, name)
+#define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \
+    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
 
 #define SetConsoleCommandShortcutExtern(function) \
-    SetConsoleCommandShortcutExternAliasMulti(function, #function, 0)
+    SetConsoleCommandShortcutExternAliasGeneric(function, #function)
 #define SetConsoleCommandShortcutExternAlias(function, name) \
-    SetConsoleCommandShortcutExternAliasMulti(function, name, 0)
-#define SetConsoleCommandShortcutExternAliasMulti(function, name, number) \
-    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
+    SetConsoleCommandShortcutExternAliasGeneric(function, name)
+#define SetConsoleCommandShortcutExternAliasGeneric(function, name) \
+    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
 
 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \
Index: code/trunk/src/core/CorePrecompiledHeaders.h
===================================================================
--- code/trunk/src/core/CorePrecompiledHeaders.h	(revision 3301)
+++ code/trunk/src/core/CorePrecompiledHeaders.h	(revision 3304)
@@ -60,6 +60,4 @@
 #include <boost/shared_ptr.hpp> // 12
 #include <boost/preprocessor/cat.hpp> // 12
-// Included by both filesystem and thread but still relatively small
-#include <boost/iterator/iterator_facade.hpp> // 10
 
 // Just in case some header included windows.h
Index: code/trunk/src/core/CorePrereqs.h
===================================================================
--- code/trunk/src/core/CorePrereqs.h	(revision 3301)
+++ code/trunk/src/core/CorePrereqs.h	(revision 3304)
@@ -150,5 +150,4 @@
     class SubclassIdentifier;
     class TclBind;
-    struct TclInterpreterBundle;
     class TclThreadManager;
     class Template;
@@ -187,4 +186,8 @@
     class SimpleCommand;
     class SimpleInputState;
+
+    // multithreading
+    class Thread;
+    class ThreadPool;
 }
 
@@ -197,10 +200,15 @@
 
 // Boost
-namespace boost { namespace filesystem
-{
-    struct path_traits;
-    template <class String, class Traits> class basic_path;
-    typedef basic_path<std::string, path_traits> path;
-} }
+namespace boost
+{ 
+    namespace filesystem
+    {
+        struct path_traits;
+        template <class String, class Traits> class basic_path;
+        typedef basic_path<std::string, path_traits> path;
+    }
+    class thread;
+    class mutex;
+}
 
 // TinyXML and TinyXML++
Index: code/trunk/src/core/Executor.h
===================================================================
--- code/trunk/src/core/Executor.h	(revision 3301)
+++ code/trunk/src/core/Executor.h	(revision 3304)
@@ -246,4 +246,6 @@
             virtual ~ExecutorMember() {}
 
+            using Executor::operator();
+
             inline void operator()(T* object) const
                 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
@@ -278,4 +280,6 @@
                 { ((FunctorMember<T>*)this->functor_)->setObject(object); }
 
+            using Executor::parse;
+
             bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
             {
Index: code/trunk/src/core/Game.cc
===================================================================
--- code/trunk/src/core/Game.cc	(revision 3301)
+++ code/trunk/src/core/Game.cc	(revision 3304)
@@ -40,4 +40,5 @@
 #include "util/Debug.h"
 #include "util/Exception.h"
+#include "util/Sleep.h"
 #include "util/SubString.h"
 #include "Clock.h"
@@ -95,8 +96,11 @@
             SetConfigValue(statisticsAvgLength_, 1000000)
                 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
+            SetConfigValue(fpsLimit_, 50)
+                .description("Sets the desired framerate (0 for no limit).");
         }
 
         unsigned int statisticsRefreshCycle_;
         unsigned int statisticsAvgLength_;
+        unsigned int fpsLimit_;
     };
 
@@ -192,9 +196,20 @@
 
         // START GAME
-        this->gameClock_->capture(); // first delta time should be about 0 seconds
+        // first delta time should be about 0 seconds
+        this->gameClock_->capture();
+        // A first item is required for the fps limiter
+        StatisticsTickInfo tickInfo = {0, 0};
+        statisticsTickTimes_.push_back(tickInfo);
         while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0))
         {
+            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
+
+            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_);
+            if (currentTime < nextTickTime)
+            {
+                usleep(nextTickTime - currentTime);
+                continue;
+            }
             this->gameClock_->capture();
-            uint64_t currentTime = this->gameClock_->getMicroseconds();
 
             // STATISTICS
Index: code/trunk/src/core/IRC.cc
===================================================================
--- code/trunk/src/core/IRC.cc	(revision 3301)
+++ code/trunk/src/core/IRC.cc	(revision 3304)
@@ -47,5 +47,5 @@
     {
         RegisterRootObject(IRC);
-        this->bundle_ = 0;
+        this->interpreter_ = 0;
     }
 
@@ -54,12 +54,12 @@
         unsigned int threadID = IRC_TCL_THREADID;
         TclThreadManager::createID(threadID);
-        this->bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);
+        this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID);
 
         try
         {
-            this->bundle_->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
         }
         catch (Tcl::tcl_error const &e)
@@ -81,5 +81,5 @@
     bool IRC::eval(const std::string& command)
     {
-        if (!IRC::getInstance().bundle_)
+        if (!IRC::getInstance().interpreter_)
         {
             IRC::getInstance().initialize();
@@ -90,5 +90,5 @@
         try
         {
-            IRC::getInstance().bundle_->interpreter_->eval(command);
+            IRC::getInstance().interpreter_->eval(command);
             return true;
         }
Index: code/trunk/src/core/IRC.h
===================================================================
--- code/trunk/src/core/IRC.h	(revision 3301)
+++ code/trunk/src/core/IRC.h	(revision 3304)
@@ -59,5 +59,5 @@
             ~IRC() {}
 
-            TclInterpreterBundle* bundle_;
+            Tcl::interpreter* interpreter_;
             std::string nickname_;
     };
Index: code/trunk/src/core/TclThreadManager.cc
===================================================================
--- code/trunk/src/core/TclThreadManager.cc	(revision 3301)
+++ code/trunk/src/core/TclThreadManager.cc	(revision 3304)
@@ -30,4 +30,7 @@
 
 #include <boost/bind.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
 #include <OgreTimer.h>
 #include <cpptcl/cpptcl.h>
@@ -56,7 +59,36 @@
     SetConsoleCommand(TclThreadManager, flush,   false).argumentCompleter(0, autocompletion::tclthreads());
 
+    struct TclInterpreterBundle
+    {
+        unsigned int id_;
+
+        std::list<std::string> queue_;
+        boost::mutex queueMutex_;
+
+        Tcl::interpreter* interpreter_;
+        std::string interpreterName_;
+        boost::try_mutex interpreterMutex_;
+
+        std::list<unsigned int> queriers_;
+        boost::mutex queriersMutex_;
+
+        bool running_;
+        boost::mutex runningMutex_;
+
+        bool finished_;
+        boost::mutex finishedMutex_;
+        boost::condition finishedCondition_;
+    };
+
+
+    static boost::thread::id threadID_g;
+    static boost::mutex bundlesMutex_g;
+    static boost::condition fullQueueCondition_g;
+    static boost::condition orxonoxEvalCondition_g;
+
     TclThreadManager* TclThreadManager::singletonRef_s = 0;
 
     TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter)
+        : orxonoxInterpreterBundle_(new TclInterpreterBundle())
     {
         RegisterRootObject(TclThreadManager);
@@ -66,11 +98,7 @@
 
         this->threadCounter_ = 0;
-        this->orxonoxInterpreterBundle_.id_ = 0;
-        this->orxonoxInterpreterBundle_.interpreter_ = interpreter;
-#if (BOOST_VERSION >= 103500)
-        this->threadID_ = boost::this_thread::get_id();
-#else
-        //
-#endif
+        this->orxonoxInterpreterBundle_->id_ = 0;
+        this->orxonoxInterpreterBundle_->interpreter_ = interpreter;
+        threadID_g = boost::this_thread::get_id();
     }
 
@@ -79,5 +107,5 @@
         unsigned int threadID;
         {
-            boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
             if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
                 return;
@@ -87,4 +115,6 @@
         this->destroy(threadID);
 
+        delete this->orxonoxInterpreterBundle_;
+
         singletonRef_s = 0;
     }
@@ -92,5 +122,5 @@
     unsigned int TclThreadManager::create()
     {
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         TclThreadManager::getInstance().threadCounter_++;
         std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_);
@@ -132,20 +162,12 @@
                     if (bundle->finished_)
                     {
-                        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
-#if (BOOST_VERSION >= 103500)
+                        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
                         boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
-#else
-                        boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
-#endif
                         try
                         {
                             while (!interpreter_lock.try_lock())
                             {
-                                TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+                                orxonoxEvalCondition_g.notify_one();
                                 boost::this_thread::yield();
-#else
-                                boost::thread::yield();
-#endif
                             }
                         } catch (...) {}
@@ -157,10 +179,6 @@
                 }
 
-                TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+                orxonoxEvalCondition_g.notify_one();
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
             }
 
@@ -181,5 +199,5 @@
     std::string TclThreadManager::query(unsigned int threadID, const std::string& command)
     {
-        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
+        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command);
     }
 
@@ -191,6 +209,6 @@
         output += "\t\t";
         {
-            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queueMutex_);
-            output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queue_.size());
+            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_);
+            output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size());
         }
         output += "\t\t";
@@ -198,5 +216,5 @@
         COUT(0) << output << std::endl;
 
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
         {
@@ -209,9 +227,5 @@
             output += "\t\t";
             {
-#if (BOOST_VERSION >= 103500)
                 boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
-#else
-                boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
-#endif
                 if (interpreter_lock.try_lock())
                     output += "ready";
@@ -228,5 +242,5 @@
         if (threadID == 0)
         {
-            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
+            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
             COUT(0) << "Queue dump of Orxonox:" << std::endl;
         }
@@ -254,5 +268,5 @@
         TclInterpreterBundle* bundle = 0;
         if (threadID == 0)
-            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
+            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
         else
             if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
@@ -334,5 +348,5 @@
     TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID)
     {
-        boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID);
         if (it != this->interpreterBundles_.end())
@@ -347,4 +361,9 @@
     }
 
+    Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID)
+    {
+        return this->getInterpreterBundle(threadID)->interpreter_;
+    }
+
     std::string TclThreadManager::dumpList(const std::list<unsigned int>& list)
     {
@@ -362,18 +381,10 @@
     void TclThreadManager::error(const std::string& error)
     {
-#if (BOOST_VERSION >= 103500)
-        if (boost::this_thread::get_id() != this->threadID_)
-#else
-        if (boost::thread() != this->threadID_)
-#endif
-        {
-            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-            if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
-            {
-#if (BOOST_VERSION >= 103500)
+        if (boost::this_thread::get_id() != threadID_g)
+        {
+            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            {
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
                 return;
             }
@@ -385,18 +396,10 @@
     void TclThreadManager::debug(const std::string& error)
     {
-#if (BOOST_VERSION >= 103500)
-        if (boost::this_thread::get_id() != this->threadID_)
-#else
-        if (boost::thread() != this->threadID_)
-#endif
-        {
-            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-            if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
-            {
-#if (BOOST_VERSION >= 103500)
+        if (boost::this_thread::get_id() != threadID_g)
+        {
+            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            {
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
                 return;
             }
@@ -408,23 +411,23 @@
     void TclThreadManager::pushCommandToQueue(const std::string& command)
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        while (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
-            this->fullQueueCondition_.wait(queue_lock);
-
-        this->orxonoxInterpreterBundle_.queue_.push_back(command);
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            fullQueueCondition_g.wait(queue_lock);
+
+        this->orxonoxInterpreterBundle_->queue_.push_back(command);
     }
 
     void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command)
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        this->orxonoxInterpreterBundle_.queue_.push_front(command);
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        this->orxonoxInterpreterBundle_->queue_.push_front(command);
     }
 
     std::string TclThreadManager::popCommandFromQueue()
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        std::string temp = this->orxonoxInterpreterBundle_.queue_.front();
-        this->orxonoxInterpreterBundle_.queue_.pop_front();
-        this->fullQueueCondition_.notify_one();
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        std::string temp = this->orxonoxInterpreterBundle_->queue_.front();
+        this->orxonoxInterpreterBundle_->queue_.pop_front();
+        fullQueueCondition_g.notify_one();
         return temp;
     }
@@ -432,6 +435,6 @@
     bool TclThreadManager::queueIsEmpty()
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        return this->orxonoxInterpreterBundle_.queue_.empty();
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        return this->orxonoxInterpreterBundle_->queue_.empty();
     }
 
@@ -505,12 +508,8 @@
         if (querier)
         {
-            if (this->updateQueriersList(querier, &this->orxonoxInterpreterBundle_))
-            {
-#if (BOOST_VERSION >= 103500)
-                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#else
-                boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#endif
-                this->orxonoxEvalCondition_.wait(interpreter_lock);
+            if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_))
+            {
+                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
+                orxonoxEvalCondition_g.wait(interpreter_lock);
 
                 if (!CommandExecutor::execute(command, false))
@@ -521,6 +520,6 @@
             }
 
-            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_.queriersMutex_);
-            this->orxonoxInterpreterBundle_.queriers_.clear();
+            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_);
+            this->orxonoxInterpreterBundle_->queriers_.clear();
         }
         return output;
@@ -533,5 +532,5 @@
             target = this->getInterpreterBundle(threadID);
         else
-            target = &this->orxonoxInterpreterBundle_;
+            target = this->orxonoxInterpreterBundle_;
 
         std::string output = "";
@@ -542,5 +541,5 @@
                 querier = this->getInterpreterBundle(querierID);
             else
-                querier = &this->orxonoxInterpreterBundle_;
+                querier = this->orxonoxInterpreterBundle_;
 
             if (querier)
@@ -548,9 +547,5 @@
                 if (this->updateQueriersList(querier, target))
                 {
-#if (BOOST_VERSION >= 103500)
                     boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
-#else
-                    boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
-#endif
                     bool successfullyLocked = false;
                     try
@@ -562,9 +557,5 @@
                             while (!interpreter_lock.try_lock())
                             {
-#if (BOOST_VERSION >= 103500)
                                 boost::this_thread::yield();
-#else
-                                boost::thread::yield();
-#endif
                             }
 
@@ -599,14 +590,10 @@
     {
         {
-            this->orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+            orxonoxEvalCondition_g.notify_one();
             boost::this_thread::yield();
-#else
-            boost::thread::yield();
-#endif
-        }
-
-        {
-            boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+        }
+
+        {
+            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
             for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
             {
@@ -626,9 +613,5 @@
 
         {
-#if (BOOST_VERSION >= 103500)
-            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#else
-            boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#endif
+            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
             unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
             Ogre::Timer timer;
@@ -644,5 +627,5 @@
     std::list<unsigned int> TclThreadManager::getThreadList() const
     {
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         std::list<unsigned int> threads;
         for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
@@ -654,9 +637,5 @@
     {
         TclThreadManager::getInstance().debug("TclThread_execute: " + command);
-#if (BOOST_VERSION >= 103500)
         boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
-#else
-        boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
-#endif
         try
         {
Index: code/trunk/src/core/TclThreadManager.h
===================================================================
--- code/trunk/src/core/TclThreadManager.h	(revision 3301)
+++ code/trunk/src/core/TclThreadManager.h	(revision 3304)
@@ -32,36 +32,14 @@
 #include "CorePrereqs.h"
 
+#include <cassert>
 #include <list>
 #include <map>
 #include <string>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
-
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
 {
-    struct _CoreExport TclInterpreterBundle
-    {
-        unsigned int id_;
-
-        std::list<std::string> queue_;
-        boost::mutex queueMutex_;
-
-        Tcl::interpreter* interpreter_;
-        std::string interpreterName_;
-        boost::try_mutex interpreterMutex_;
-
-        std::list<unsigned int> queriers_;
-        boost::mutex queriersMutex_;
-
-        bool running_;
-        boost::mutex runningMutex_;
-
-        bool finished_;
-        boost::mutex finishedMutex_;
-        boost::condition finishedCondition_;
-    };
+    // Internal struct
+    struct TclInterpreterBundle;
 
     class _CoreExport TclThreadManager : public OrxonoxClass
@@ -101,4 +79,5 @@
 
             Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
+            Tcl::interpreter* getTclInterpreter(unsigned int threadID);
             TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
             std::string dumpList(const std::list<unsigned int>& list);
@@ -119,14 +98,6 @@
 
             unsigned int threadCounter_;
-            TclInterpreterBundle orxonoxInterpreterBundle_;
+            TclInterpreterBundle* orxonoxInterpreterBundle_;
             std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;
-            boost::mutex bundlesMutex_;
-            boost::condition fullQueueCondition_;
-            boost::condition orxonoxEvalCondition_;
-#if (BOOST_VERSION >= 103500)
-            boost::thread::id threadID_;
-#else
-            boost::thread threadID_;
-#endif
 
             static TclThreadManager* singletonRef_s;
Index: code/trunk/src/core/Thread.cc
===================================================================
--- code/trunk/src/core/Thread.cc	(revision 3304)
+++ code/trunk/src/core/Thread.cc	(revision 3304)
@@ -0,0 +1,129 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Thread.h"
+
+#include <cassert>
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include "util/Sleep.h"
+#include "Executor.h"
+
+namespace orxonox
+{
+    boost::posix_time::millisec THREAD_WAIT_BEFORE_DETACH(1000);
+    
+    
+    Thread::Thread():
+        executor_(0),
+        isWorking_(false),
+        stopThread_(false)
+    {
+        this->executorMutex_ = new boost::mutex;
+        this->isWorkingMutex_ = new boost::mutex;
+        this->stopThreadMutex_ = new boost::mutex;
+        this->workerThread_ = new boost::thread( boost::bind(&Thread::threadLoop, this) );
+    }
+    
+    Thread::~Thread()
+    {
+        this->stopThreadMutex_->lock();
+        this->stopThread_ = true;
+        this->stopThreadMutex_->unlock();
+        if( !this->workerThread_->timed_join( THREAD_WAIT_BEFORE_DETACH ) )
+            assert(0); // this should not happen
+        delete this->workerThread_;
+        delete this->executorMutex_;
+        delete this->stopThreadMutex_;
+        delete this->isWorkingMutex_;
+    }
+    
+    bool Thread::isWorking()
+    {
+      this->isWorkingMutex_->lock();
+      bool isWorking = this->isWorking_;
+      this->isWorkingMutex_->unlock();
+      return isWorking;
+    }
+    
+    bool Thread::evaluateExecutor( Executor* executor )
+    {
+        this->isWorkingMutex_->lock();
+        this->isWorking_=true;
+        this->isWorkingMutex_->unlock();
+        this->executorMutex_->lock();
+        this->executor_ = executor;
+        this->executorMutex_->unlock();
+        return true;
+    }
+    
+    void Thread::threadLoop()
+    {
+        bool stopThread = false;
+        while( !stopThread )
+        {
+            //this->executorMutex_->lock();
+            Executor* executor = this->executor_;
+            //this->executorMutex_->unlock();
+            if( executor )
+            {
+                (*executor)();
+                this->executorMutex_->lock();
+                delete this->executor_;
+                this->executor_ = 0;
+                this->executorMutex_->unlock();
+                this->isWorkingMutex_->lock();
+                this->isWorking_=false;
+                this->isWorkingMutex_->unlock();
+            }
+            else
+            {
+                this->workerThread_->yield();
+            }
+            //this->stopThreadMutex_->lock();
+            stopThread = this->stopThread_;
+            //this->stopThreadMutex_->unlock();
+        }
+    }
+    
+    void Thread::waitUntilFinished()
+    {
+        bool stillWorking = true;
+        while( stillWorking )
+        {
+            this->isWorkingMutex_->lock();
+            stillWorking = this->isWorking_;
+            this->isWorkingMutex_->unlock();
+            if( stillWorking )
+                msleep( 1 );
+        }
+    }
+}
Index: code/trunk/src/core/Thread.h
===================================================================
--- code/trunk/src/core/Thread.h	(revision 3304)
+++ code/trunk/src/core/Thread.h	(revision 3304)
@@ -0,0 +1,64 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Thread_H__
+#define _Thread_H__
+
+#include "CorePrereqs.h"
+
+namespace boost{
+  class recursive_mutex;
+}
+
+ namespace orxonox
+{
+    class _CoreExport Thread
+    {
+    public:
+        Thread();
+        virtual ~Thread();
+
+        bool isWorking();
+        void waitUntilFinished();
+        bool evaluateExecutor( Executor* executor );
+
+    private:
+        void            threadLoop();
+        
+        Executor*       executor_;
+        bool            isWorking_;
+        bool            stopThread_;
+        boost::thread*  workerThread_;
+        boost::mutex*   executorMutex_;
+        boost::mutex*     isWorkingMutex_;
+        boost::mutex*   stopThreadMutex_;
+    };
+
+ }
+
+#endif /* _Thread_H__ */
Index: code/trunk/src/core/ThreadPool.cc
===================================================================
--- code/trunk/src/core/ThreadPool.cc	(revision 3304)
+++ code/trunk/src/core/ThreadPool.cc	(revision 3304)
@@ -0,0 +1,115 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ThreadPool.h"
+#include "Thread.h"
+#include <cassert>
+
+namespace orxonox
+{
+
+    ThreadPool::ThreadPool()
+    {
+    }
+    
+    ThreadPool::~ThreadPool()
+    {
+        unsigned int a = this->setNrOfThreads(0);
+        assert(a == 0);
+    }
+    
+    void ThreadPool::addThreads( unsigned int nr )
+    {
+        for( unsigned int i=0; i<nr; i++ )
+            this->threadPool_.push_back(new Thread());
+    }
+    unsigned int ThreadPool::removeThreads( unsigned int nr )
+    {
+        unsigned int i=0;
+        std::vector<Thread*>::iterator it;
+        for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; )
+        {
+            if( ! (*it)->isWorking() )
+            {
+                Thread* temp = *it;
+                it=this->threadPool_.erase( it );
+                delete temp;
+                ++i;
+            }
+            else
+              ++it;
+        }
+        return i;
+    }
+    unsigned int ThreadPool::setNrOfThreads( unsigned int nr )
+    {
+        unsigned int currentsize = this->threadPool_.size();
+        if ( nr < currentsize )
+            return currentsize - removeThreads( currentsize - nr );
+        else if ( nr == currentsize )
+            return currentsize;
+        else
+        {
+            addThreads( nr - currentsize );
+            return nr;
+        }
+    }
+    
+    bool ThreadPool::passFunction( Executor* executor, bool addThread )
+    {
+        std::vector<Thread*>::iterator it;
+        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
+        {
+            if ( ! (*it)->isWorking() )
+            {
+                bool b = (*it)->evaluateExecutor( executor );
+                assert(b); // if b is false then there is some code error
+                return true;
+            }
+        }
+        if ( addThread )
+        {
+            addThreads( 1 );
+            bool b = this->threadPool_.back()->evaluateExecutor( executor ); // access the last element
+            assert(b);
+            return true;
+        }
+        else
+            return false;
+    }
+    
+    void ThreadPool::synchronise()
+    {
+        std::vector<Thread*>::iterator it;
+        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
+        {
+            (*it)->waitUntilFinished();
+        }
+    }
+
+}
Index: code/trunk/src/core/ThreadPool.h
===================================================================
--- code/trunk/src/core/ThreadPool.h	(revision 3304)
+++ code/trunk/src/core/ThreadPool.h	(revision 3304)
@@ -0,0 +1,57 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ThreadPool_H__
+#define _ThreadPool_H__
+
+#include "CorePrereqs.h"
+
+#include <vector>
+
+ namespace orxonox
+{
+    class _CoreExport ThreadPool
+    {
+    public:
+        ThreadPool();
+        virtual ~ThreadPool();
+        
+        void addThreads( unsigned int nr );
+        unsigned int removeThreads( unsigned int nr );
+        unsigned int setNrOfThreads( unsigned int nr );
+        
+        bool passFunction( Executor* executor, bool addThread=false );
+        void synchronise();
+        
+    private:
+        std::vector<Thread*> threadPool_;
+        
+    };
+}
+
+#endif /* _ThreadPool_H__ */
