atlas-engineer / nhooks

MIT License
18 stars 5 forks source link

Unexport `*hook*`? #2

Closed Ambrevar closed 2 years ago

Ambrevar commented 2 years ago

Is it expected to re-export *hook* in nhook? Is there a use case?

kchanqvq commented 2 years ago

I think it might be useful for some introspection? For example, there can be a log-me handler, that if you add it to any hook, it will print/record some information every time that hook runs.

Ambrevar commented 2 years ago

Fair enough.

While we are at it, isn't this dynamic variable prone to race conditions? What if multiple threads run the same hook at the same time?

kchanqvq commented 2 years ago

Fair enough.

While we are at it, isn't this dynamic variable prone to race conditions? What if multiple threads run the same hook at the same time?

I'm using dynamic binding to bind *hook*, which is thread safe (implemented under the hood by thread local storage).

I looked back at serapeum's use of *hook* and it's funny... it seems to confuse lexical and dynamic variable. But whatever.

Ambrevar commented 2 years ago

As far as I understand, thread local storage must be made explicit in Bordeeaux threads, using the :initial-bindings keyword argument. Dynamic bindings are not thread-safe otherwise, but I could be wrong.

kchanqvq commented 2 years ago

As far as I understand, thread local storage must be made explicit in Bordeeaux threads, using the :initial-bindings keyword argument. Dynamic bindings are not thread-safe otherwise, but I could be wrong.

That is for initializing "thread-local global bindings". I'm pretty sure "local bindings" are thread-safe on all major CL implementations. E.g. http://www.sbcl.org/manual/#Special-Variables