|
Various C++ Examples (including IPC)
Version: 1.0.0
|
A basic thread management class. More...

Classes | |
| struct | func_arguments |
| structure for static wrapper function arguments More... | |
Public Member Functions | |
| ThreadMgr () | |
| constructor More... | |
| int | cancel_thread (pthread_t *tid) |
| cancel a thread More... | |
| int | condWait (void **thread_return_val) |
| wait on a condition variable for a thread to terminate More... | |
| pthread_t | createThread (void *(*thread_func)(void *), void *arg) |
| attempt to create a new thread and register it More... | |
| int | threadsActive () |
| return the number of active threads More... | |
| bool | no_threads_terminated () |
| answers the question "are there no theads terminated?" More... | |
Protected Member Functions | |
| int | removeTerminated (void **return_val) |
| remove a terminated thread LIFO More... | |
| void | addID (pthread_t id, func_arguments *arg) |
| add a thread id to the id vector More... | |
Static Protected Member Functions | |
| static void * | func (void *arg) |
| internal thread function More... | |
| static void * | addTerminated (ThreadMgr *arg) |
| add a thread id to the m_terminated stack More... | |
| static void | shutdown_thread (void *arg) |
| shutdown a thread from pthread_cleanup_pop(). More... | |
Private Attributes | |
| pthread_mutex_t * | m_mutex |
| mutex for data access (m_ids, m_terminated) More... | |
| pthread_mutex_t * | m_cond_mutex |
| mutex for condition variable More... | |
| pthread_cond_t * | m_cond_var |
| condition variable More... | |
| std::map< pthread_t, ThreadMgr::func_arguments * > | m_ids |
| map of all thread ids and function attributes More... | |
| std::stack< pthread_t > | m_terminated |
| stack of terminated thread ids More... | |
A basic thread management class.
Definition at line 60 of file threadDeath3.cc.
|
inline |
constructor
Definition at line 80 of file threadDeath3.cc.
References m_cond_mutex, m_cond_var, and m_mutex.
|
inlineprotected |
add a thread id to the id vector
Definition at line 386 of file threadDeath3.cc.
References m_ids, and m_mutex.
Referenced by createThread().
|
inlinestaticprotected |
add a thread id to the m_terminated stack
Definition at line 317 of file threadDeath3.cc.
References m_cond_var, m_mutex, and m_terminated.
Referenced by func().
|
inline |
cancel a thread
| tid | pointer to the thread id to kill |
Definition at line 100 of file threadDeath3.cc.
References m_ids, and m_mutex.
Referenced by main().
|
inline |
wait on a condition variable for a thread to terminate
| a | pointer to the pointer of the threads return value. |
Definition at line 140 of file threadDeath3.cc.
References m_cond_mutex, m_cond_var, no_threads_terminated(), and removeTerminated().
Referenced by main(), TwaitStringThreads(), and waitStringThreads().

|
inline |
attempt to create a new thread and register it
| pointer | to function to run as thread, pointer to argument. [i.e. createThread(myfunc, arg);] |
Definition at line 181 of file threadDeath3.cc.
References addID(), ThreadMgr::func_arguments::arg, ThreadMgr::func_arguments::cancel_func, ThreadMgr::func_arguments::func, and ThreadMgr::func_arguments::thisObject.
Referenced by main().

|
inlinestaticprotected |
internal thread function
| arg | shold be a pointer to a func_arguments structure. |
Definition at line 265 of file threadDeath3.cc.
References addTerminated(), ThreadMgr::func_arguments::arg, ThreadMgr::func_arguments::cancel_func, ThreadMgr::func_arguments::func, shutdown_thread(), and ThreadMgr::func_arguments::thisObject.

|
inline |
answers the question "are there no theads terminated?"
Definition at line 251 of file threadDeath3.cc.
References m_mutex, and m_terminated.
Referenced by condWait(), and main().
|
inlineprotected |
remove a terminated thread LIFO
| pointer | to user function return value pointer |
Definition at line 336 of file threadDeath3.cc.
References m_ids, m_mutex, and m_terminated.
Referenced by condWait().
|
inlinestaticprotected |
shutdown a thread from pthread_cleanup_pop().
| arg | must be void * per pthread_cleanup_x() |
Definition at line 399 of file threadDeath3.cc.
Referenced by func().
|
inline |
return the number of active threads
Definition at line 241 of file threadDeath3.cc.
References m_ids, and m_mutex.
Referenced by main(), TwaitStringThreads(), and waitStringThreads().
|
private |
mutex for condition variable
Definition at line 413 of file threadDeath3.cc.
Referenced by condWait(), and ThreadMgr().
|
private |
condition variable
Definition at line 416 of file threadDeath3.cc.
Referenced by addTerminated(), condWait(), and ThreadMgr().
|
private |
map of all thread ids and function attributes
Definition at line 419 of file threadDeath3.cc.
Referenced by addID(), cancel_thread(), removeTerminated(), and threadsActive().
|
private |
mutex for data access (m_ids, m_terminated)
Definition at line 410 of file threadDeath3.cc.
Referenced by addID(), addTerminated(), cancel_thread(), no_threads_terminated(), removeTerminated(), ThreadMgr(), and threadsActive().
|
private |
stack of terminated thread ids
Definition at line 422 of file threadDeath3.cc.
Referenced by addTerminated(), no_threads_terminated(), and removeTerminated().