[Basisklasse Async.-Ausführung] Verbesserungsvorschläge?



  • Hallo,

    Ich habe mir eine kleine Klasse gebaut, mit deren Hilfe eine beliebige Operation asynchron ausgeführt werden kann.
    Dazu muss nur von der Klasse abgeleitet werden, und eine rein-virtuelle Methode überschrieben werden.

    Nun möchte ich wissen, was ihr davon haltet, ob sie Threadsafe ist usw. usw.

    Ich weiß, dass das ganze nicht allzu toll ist, es ist auch mein erster Versuch mit Multithreading, trotzdem hoffe ich, dass dies halbwegs "sicher" ist^^

    Hier die Klasse:

    class async_executor
    {
    	public:
    		async_executor()
    		: m_is_ready(false)
    		{
    		}
    
    		bool is_ready()
    		{
    			boost::mutex::scoped_lock lock(m_mutex);
    
    			return m_is_ready;
    		}
    
    		void start_async_operation()
    		{
    			boost::thread t(boost::bind(&async_executor::start_operation_thread, this));
    		}
    
    	protected:
    		virtual void thread_func() = 0;
    
    		void set_ready()
    		{
    			boost::mutex::scoped_lock lock(m_mutex);
    			m_is_ready = true;
    		}
    
    	private:
    		void start_operation_thread()
    		{
    			this->thread_func();
    		}
    
    	private:
    		boost::mutex m_mutex;
    
    		bool m_is_ready;
    };
    

Anmelden zum Antworten