#include "base.hh"
#include "base_thread.hh"
Namespaces | |
| namespace | base |
| namespace | base::restrict |
Classes | |
| struct | base::ThreadMemoryHeader |
| Defines size and free space in "thread memory" allocated on heap. More... | |
Defines | |
| #define | BASE_THREAD_CC 1 |
| #define | INIT_ATTR(PRIORITY) |
| #define | INIT_ATTR2(PRIORITY, SCHED_GET_FUNC) |
Functions | |
| static void * | base::ThreadMemory_Align (void *const p) |
| static void | base::ThreadMemory_WriteHeader (void *block, const uint size) |
| static bool | base::ThreadMemory_SetFreeSpace (void *block, void *freeSpace) |
| static void * | base::ThreadMemory_GetFreeSpace (void *block) |
| static void | base::ThreadMemory_CheckSignature (const void *block) |
| void * | base::SuballocateThreadMemory (const uint bytes) |
Variables | |
| static const uint32 | base::THREAD_MEMORY_SIG = 0xdead8086 |
| __thread int | base::restrict::gAtomicTid |
Thread memory: -------------- Per-thread memory is managed by the Thread class. When a new thread is spawned, a large memory block is allocated on the heap, and the whole block is freed when the thread ends. PerThreadPtr suballocates thread memory, using pthreads keys to map one thread to one suballocated block.
The bottom of the thread memory has a header struct, that defines the block's size and free space. SuballocateThreadMemory() advances the pointer for every segment allocated. For simplicity, suballocated segments aren't freed, rather, the whole block will be freed when the thread ends.
Thread-local storage (TLS): --------------------------- Some operating-systems provide TLS by remapping pages during a thread switch. pthreads defers allocating per-thread memory to the application, and only provides per-thread magic pointers via pthreads_setspecific/getspecific().
pthreads problems: ------------------ A problem was that threads were exhausing virtual memory. By default, threads are joinable, which means a thread will turn into a zombie if no other thread joins. This is solved by pthread_detach().
Crash during program exit occurred, evidently, while other threads were still running while main thread was executing C++ destructors. Solutions was to call _exit() which forcibly exits the process.
GNU GCC TLS: ------------ "The only real limitation is that in C++ programs thread-local variables must not require a PERSISTENT constructor."
GNU GCC mcheck: --------------- Don't link with -lmcheck. mcheck isn't thread-safe.
| #define BASE_THREAD_CC 1 |
| #define INIT_ATTR | ( | PRIORITY | ) |
Value:
{ \
mPthreadAttr.resize( PRIORITY + 1 ); \
PTHREAD_CALL( pthread_attr_init( &mPthreadAttr[PRIORITY] ) ); \
}
| #define INIT_ATTR2 | ( | PRIORITY, | |||
| SCHED_GET_FUNC | ) |
Value:
{ \
sched_param schedParam; \
schedParam.sched_priority = SCHED_GET_FUNC( SCHED_OTHER ); \
ASSERT( schedParam.sched_priority != -1 ); \
pthread_attr_setschedparam( &mPthreadAttr[PRIORITY], &schedParam ); \
}
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:13 2007