Is there a good, platform-agnostic way to implement a variable that's local to both a thread and a class instance, i.e. if you have T threads and I class instances, you have TxI instances of that variable? I'm using the D programming language, version 2, but a good language-agnostic answer would also be useful.
Here are some constraints:
- Must never require synchronization. This rules out having a hash table mapping thread ID to variable reference as a member variable.
- Must not keep references around that should be garbage-collected. This rules out having a thread-local, static hash table indexed by class instance.
- Initialization should be lazy for efficiency. If a thread never accesses a given instance's variable then it should never be created.