TLS example
Assume the data definition is:
typedef struct _rslb {
FILE* f;
char name[MAX_PATH];
} RSLB;
The above code reserves a new TLS index at process attach and frees that index at process detach.
When a new thread is created (and when the process attaches) a new instance of RSLB is allocated and the pointer is saved in TLS. A filename is then set up and a file is created. At thread detaching, the file is closed and the RSLB instance is freed.
As an example, when a function in the RSL needs to write to the current thread’s file, code like this is required:
RSLB* pRslb;
pRslb = RtTlsGetValue(iRslb);
fwrite(buf, size, count, pRslb->f);
A more involved RSL example that also uses TLS can be found in project “service” of the “INtime Service process sample” installed with the SDK.