Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-30 Thread Jiacai Liu
Oh, it's the same issue with your first example, we need to change executor that core/async use. I will add some hook to decorate those frequently-used executor. On Sunday, July 30, 2017 at 3:32:34 PM UTC+8, Didier wrote: > > I think it would be nice if inheritable-var would set! the future

Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-30 Thread Didier
I think it would be nice if inheritable-var would set! the future executor service on load, so the user doesn't have to. This way it will just work with future also. Just my 2 cent. Here's how to reproduce the issue with core.async: (let [t 1000] (dotimes [x t] (let [foo (inheritable-var

Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-30 Thread Jiacai Liu
For your first example, we should decorate the executor future use, see TransmittableThreadLocal doc (let [foo (inheritable-var (constantly "Main"))] (set!

Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-29 Thread Didier
For the core.async example, it was my mistake. Forgot to definheritable foo. The example does not return an exception, but "Main Thread", showing that the inheritable did not work. If using async/thread it does work though. On Saturday, 29 July 2017 08:07:08 UTC-7, Jiacai Liu wrote: > >

Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-29 Thread Didier
Your doc says this doesn't work with dynamic binding: (def ^:dynamic *foo* 5) (defn adder [param] (+ *foo* param)) (binding [*foo* 10] (doseq [v (pmap adder (repeat 3 5))] (println v))) But it does since Clojure 1.3. They added binding conveyance:

Re: [inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-29 Thread Jiacai Liu
Thanks for your tips. I have updated my code to wrap TransmittableThreadLocal , an enhanced version of InheritableThreadLocal, to solve threadpool problem. On Sunday, July 30, 2017 at 3:11:59 AM UTC+8, Didier

[inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-29 Thread Didier
InheritableThreadLocal is not safe to use with ThreadPools. And a lot of the Clojure parallel constructs rely on ThreadPools. I'd recommend you rely on dynamic Vars instead and use bound-fn when you want child threads to inherit parent's bindings. If you knew this already, then I see no harm

[inheritable-var] A wrapper of InheritableThreadLocal to define thread-inheritable variable

2017-07-29 Thread Jiacai Liu
After digging into dynamic + binding doesn't work in multithread, I create a simple wrap to define thread-inheritable var. Any suggestions(bugs) are welcome. https://github.com/jiacai2050/inheritable-var -- You received this message because you are subscribed to the Google Groups "Clojure"