RDBI / rdbi

rdbi is an attempt to rewrite the core of Ruby/DBI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread local usage

raggi opened this issue · comments

In order to be a good citizen, the ideal thing is to try to reduce the volume of thread local usage.

There are a few approaches to this, but one that can work quite well is to store a key for the thread by package. The problem with this approach is that it could create small reference leaks:

@thread_locals = Hash.new { |h,k| h[k] = {} }
@thread_locals[Thread.current.object_id][:foo] = :something

Cleaning this up can be hard, but for pooled data it should be possible to have hooks in the pool to clean it up.

Hrm. So you're saying that attr_threaded_accessor is the wrong approach?

I'm not sure tbh, the problem is that thread local storage is basically globals.

Right, attr_threaded_accessor basically obfuscates that; check the impl out in methlab.

Closing. Unclear to me what this applied to.