[CLJ-1077] thread-bound? returns true (implying set! should succeed) even for non-binding thread Created: 26/Sep/12 Updated: 21/Jul/15
thread-bound? returns true for a non-binding thread, this result (according to the docstring) implies that set! should succeed. However, thread-bound? does not check that any binding that might exist was created by the current thread, and calling set! fails with an exception when it is called from a non-binding thread, even though thread-bound? returns true.
thread-bound? should return false if there is a binding, and that binding was not established by the current thread.
Here is an example REPL session where a thread establishes a binding, those bindings are conveyed to a second thread, the second thread checks thread-bound? to see if it can set the binding, thread-bound? returns true indicating that the binding can be set, the second thread tries to set the binding, and the second thread gets an IllegalStateException:
|Comment by Paul Stadig [ 01/Oct/12 10:07 AM ]|
I have attached a patch that changes clojure.lang.Var and clojure.core/thread-bound? to only return true if a Var is set!-able.
|Comment by Alex Miller [ 19/Aug/13 12:16 PM ]|
|Comment by Joe Gallo [ 20/Aug/13 7:55 AM ]|
Sure thing, Alex – here's a repl example I just ran this morning.