Closed simeonschaub closed 4 years ago
I think just using a global lock for this would be fine?
That should work as well. I was only worried about the overhead of such a global lock, but perhaps that is relatively small compared to creating RuntimeGeneratedFunction
s in the first place.
Overhead should be insignificant; it's only hit when constructing and compiling the RuntimeGeneratedFunction
. If those are hot code paths, you've probably got other problems ;-)
Actually I think the compiler still holds various locks so the @generated
part may be locked as a side effect of something else. But not so for the construction side of things.
In general the compiler doesn't seem to like locks held inside @generated
, but hopefully #11 is a valid way to do this.
The current approach just creates and modifies a global Dict, which can cause problems when creating
RuntimeGeneratedFunction
s from different threads. I think a workaround for this might be to just create an array ofThreads.nthreads()
Dicts instead and only let the constructor modify the Dict atThreads.threadid()
. If the same function is created on two different threads, we would of course have to store the expression twice, but that shouldn't be too bad.