const FunEncapsulation &fun_encapsulation,
const unsigned int n_threads);
+ /**
+ * Return the number of presently
+ * existing threads. This function
+ * may be useful in a situation
+ * where a large number of threads
+ * are concurrently, and you want
+ * to decide whether creation of
+ * another thread is reasonable or
+ * whether running the respective
+ * operation sequentially is more
+ * useful since already many more
+ * threads than processors are
+ * running.
+ *
+ * Note that the function returns
+ * the total number of threads, not
+ * those actually running. Some of
+ * the threads may be waiting for
+ * locks and mutexes, or may be
+ * sleeping until they are
+ * delivered with data to work on.
+ *
+ * Upon program start, this number
+ * is one. It is increased each
+ * time a thread is created using
+ * the @ref{Threads::spawn} or
+ * @ref{Threads::spawn_n}
+ * functions. It is decreased once
+ * a thread terminates by returning
+ * from the function that was
+ * spawned.
+ *
+ * Note that this means that only
+ * threads created and terminated
+ * through the interfaces of this
+ * namespace are taken care of. If
+ * threads are created by directly
+ * calling the respective functions
+ * of the operating system
+ * (e.g. @p{pthread_create} for the
+ * POSIX thread interface), or if
+ * they are killed (e.g. either
+ * through @p{pthread_exit} from
+ * the spawned thread, or
+ * @p{pthread_kill} from another
+ * thread), then these events are
+ * not registered and counted for
+ * the result of this function.
+ */
+ unsigned int n_existing_threads ();
/**
* Split the range @p{[begin,end)}
<< "leak somewhere.");
};
+
+ /**
+ * The following function is used
+ * for internal bookkeeping of the
+ * number of existing threads. It
+ * is not thought for use in
+ * application programs, but only
+ * for use in the template
+ * functions below.
+ */
+ void register_new_thread ();
+
+ /**
+ * The following function is used
+ * for internal bookkeeping of the
+ * number of existing threads. It
+ * is not thought for use in
+ * application programs, but only
+ * for use in the template
+ * functions below.
+ */
+ void deregister_new_thread ();
+
}; // end declarations of namespace Threads
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)();
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3);
-
+ deregister_new_thread ();
+
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)();
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+ deregister_new_thread ();
return 0;
}
// @p{fun_data}
fun_data->lock.release ();
- // call the function
+ // register new thread, call the
+ // function, and upon its return,
+ // de-register it again
+ register_new_thread ();
(object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ deregister_new_thread ();
return 0;
}