There can't be 2 threads using the same Theano function at the same time. This won't work, as their is a global structure that would be shared by the 2 computations. The only way I see that we could allow this, is to create a new structure per threads, or have many such structures that won't be shared. So even if we do this in the futur, I never see a case where we would share this structure between threads.

So I don't see a need to raise the ref count on rval. As rval is the output of that thunk, that is normally was just allocated or was the allocation of a previous call with allow_gc=False.