Library of Assembled Shared Sources
|
library to run (member) functions in a thread More...
#include <thread_fun.h>
library to run (member) functions in a thread
With these objects/functions, you can run (member) functions in threads instead of calling them directly. you even can specify the arguments to be used. Let's illustrate this with a simple example:
threadFun2 allocates a new thread with the necessary information to call the function, then creates and runs the thread. It returns a pointer to the allocated thread. If you do nothing, the thread runs in detached mode and will kill itself at completion (so you don't have to call delete
on thread
yourself. So you even don't have to catch the return value. However, if you want to run it in joinable, you'll have delete the thread yourself. DO NOT FORGET THIS! Maybe we should do something about this situation?
You can also call member functions of specific objects in the thread, both const as non-const member functions.
Limitations: