include vmm.inc
VMMCall _AllocateThreadDataSlot
cmp eax, 0
je error
mov [DataSlotOffset], eax
Allocates a thread data slot. Uses C calling conventions.
A thread data slot is a DWORD value associated with each thread. The thread data slot offset gives the location of the thread data slot that you allocated, relative to the thread handle. Essentially, _AllocateThreadDataSlot works for threads just like _Alloc_VM_CB_Area works for virtual machines, except that the size of the memory block is always four bytes for thread data slots, whereas it is user-defined for virtual machine control blocks.
Note that thread data slots are not zero-initialized. If this is important, you should zero-initialize the thread data slot yourself.
Since thread data slots are only four bytes, if you need to record more than four bytes of data on a per-thread basis, the traditional mechanism is to store a pointer to a data block in the thread data slot. Don't forget to free the data block when the thread is destroyed, or you will leak memory.
Thread data slots are scarce resources. They should be freed when no longer needed.