Subject: | ID/refaddr and thread/fork safety |
(This came up in a discussion on thread-safty on Perlmonks in reference to my module Object::LocalVars.) Using refaddr as the lookup key for inside-out data means that objects become disconnected from their data across thread creation (and, presumably forking), as the underlying memory location changes in the copy. Storing the original memory address in the blessed scalar reference and using that as a key should work, but might still have collision problems if the original reference is released and the memory location subsequently reused for another object. Using a truly unique identifier (UUID or equivalent) and storing that in the blessed scalar reference may be a safer solution.