1 /* 2 * SObjectizer-5 3 */ 4 5 /*! 6 * \file 7 * \brief Various stuff related to worker thread's join. 8 * 9 * \since 10 * v.5.6.0 11 */ 12 13 #pragma once 14 15 #include <so_5/exception.hpp> 16 #include <so_5/ret_code.hpp> 17 #include <so_5/current_thread_id.hpp> 18 19 namespace so_5 { 20 21 namespace impl { 22 23 // 24 // ensure_join_from_different_thread 25 // 26 /*! 27 * \brief Ensures that join will be called from different thread. 28 * 29 * It's a mistake if thread::join() is called from the context of 30 * thread to be joined. Unfortunately, different implementations 31 * of stdlib work differently. There can be an exception. Or there 32 * can be deadlock, or there can be memory damage. 33 * 34 * It is better to check for that error manually and throw an exception 35 * if the error is detected. 36 * 37 * \since 38 * v.5.6.0 39 */ 40 inline void ensure_join_from_different_thread(current_thread_id_t thread_to_be_joined)41ensure_join_from_different_thread( 42 current_thread_id_t thread_to_be_joined ) 43 { 44 if( query_current_thread_id() == thread_to_be_joined ) 45 SO_5_THROW_EXCEPTION( 46 rc_unable_to_join_thread_by_itself, 47 "worker thread attempts to join() itself" ); 48 } 49 50 } /* namespace impl */ 51 52 } /* namespace so_5 */ 53 54