src/thread_pthread.cpp
changeset 10403 4925650db7ae
parent 10375 947e542f2bfc
child 10860 ae89867701fe
equal deleted inserted replaced
10402:b168fbb99f7c 10403:4925650db7ae
   102 
   102 
   103 		void *ret;
   103 		void *ret;
   104 		pthread_join(m_thr, &ret);
   104 		pthread_join(m_thr, &ret);
   105 		m_thr = 0;
   105 		m_thr = 0;
   106 
   106 
       
   107 		delete this;
       
   108 
   107 		return ret;
   109 		return ret;
   108 	}
   110 	}
   109 
   111 
   110 	/* virtual */ bool IsCurrent()
   112 	/* virtual */ bool IsCurrent()
   111 	{
   113 	{
   133 	 */
   135 	 */
   134 	void *ThreadProc()
   136 	void *ThreadProc()
   135 	{
   137 	{
   136 		/* The new thread stops here so the calling thread can complete pthread_create() call */
   138 		/* The new thread stops here so the calling thread can complete pthread_create() call */
   137 		sem_wait(&m_sem_start);
   139 		sem_wait(&m_sem_start);
       
   140 
       
   141 		/* Did this thread die naturally/via exit, or did it join? */
       
   142 		bool exit = false;
   138 
   143 
   139 		/* Call the proc of the creator to continue this thread */
   144 		/* Call the proc of the creator to continue this thread */
   140 		try {
   145 		try {
   141 			m_proc(m_param);
   146 			m_proc(m_param);
   142 		} catch (...) {
   147 		} catch (...) {
       
   148 			exit = true;
   143 		}
   149 		}
   144 
   150 
   145 		/* Notify threads waiting for our completion */
   151 		/* Notify threads waiting for our completion */
   146 		sem_post(&m_sem_stop);
   152 		sem_post(&m_sem_stop);
   147 
   153 
   148 		return NULL;
   154 		if (exit) delete this;
       
   155 
       
   156 		pthread_exit(NULL);
   149 	}
   157 	}
   150 };
   158 };
   151 
   159 
   152 /* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
   160 /* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
   153 {
   161 {