Browse Prior Art Database

Thread specific storage across platform Unix/NT/OS2/Linux ...

IP.com Disclosure Number: IPCOM000012967D
Original Publication Date: 2001-Jul-18
Included in the Prior Art Database: 2003-Jun-11
Document File: 2 page(s) / 47K

Publishing Venue

IBM

Abstract

Certain thread specific data applies to all platforms. Each thread has its own pointer to a data structure which is referred by specdata pointer. Because an application can be running in multi-threaded mode, each thread must know how to store and retrieve its pointer. The proposed herein implementation uses a large global array of pointers as storage for all threads.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 56% of the total text.

Page 1 of 2

Thread specific storage across platform Unix/NT/OS2/Linux ...

    Certain thread specific data applies to all platforms. Each thread has its own pointer to a data structure which is referred by specdata pointer. Because an application can be running in multi-threaded mode, each thread must know how to store and retrieve its pointer. The proposed herein implementation uses a large global array of pointers as storage for all threads.

Each thread uses its thread ID to index to this array to set and get the specdata pointer.

1) Overload system new, delete, malloc ...

The malloc, strdup, and free commands are redefined to dtw_mem_malloc, dtw_mem_strdup, dtw_mem_free.These symbols are exported from dtwmem.dll

New and delete are not redefined like the above commands. They are overloaded by new and delete operations from dtwmem.dll. Within the memory manager module, we may use new and delete. To prevent these functions from calling themselves, we overload new and delete in each class in the memory manager module using system malloc.

2) How memory manager works

dtw_mem_init: create hash table, memory block list using system malloc. specdata is the pointer pointing to this memory area in the heap.

dtw_mem_malloc: Check to see if this is a request for real heap malloc or any piece of memory to be return, then process accordingly.

real heap malloc: return system malloc

any malloc: use memory in the block, insert this pointer to the hash table.

dtw_mem_free: Check in the hash table and the block list to see if this is a real heap pointer or a pointer in the block list.

real heap free: system free

any free: it is in the block list, so do nothing.

dtw_mem_done: Free the hash table, memory block list.

2) Thread specific storage

Each thread has its own hash table and block list which is referred by specdata pointer. Because Net.Data is running in multi-threaded mode, each thread must know how to store and retrieve its pointer. Our current implementation uses a large global array of pointers as storage for all threads. Each thread uses its thread ID to index to this array to set and get the specdata pointer.

3) Compiling code with memory manager

To enable memory manager, use /D_DTW_MEMORY in the compilation flags and then link with dtwmem.lib.

4) Pro, con and further discussion of memo...