Forum Navigation
TLS in Tango
Posted: 03/08/07 19:25:29I'm writing a wrapper around Mike Cowlishaw's decNumber library for Binary Coded Decimals.
I'm making it a work alike of Python's Decimals module. To do this, I need to implement the getcontext() and setcontext() functions. These are very simple functions: getcontext() returns the default decimal context, setcontext() changes the default context. Contexts, BTW, are just D classes with some wrapped C structs and function calls.
The only caveat is that getcontext() and setcontext() need to work off of Thread Local Storage (TLS). Different threads need to have different default contexts, and when one thread's context changes another's must not.
I see that there is a ThreadLocal? class in Tango, but it's not obvious to me how to use it (I'm just learning D now). Can someone give me an example of allocating a class from TLS with Tango?
Thanx,
Brian