Skip to content

Commit 03d6323

Browse files
committed
Merge branch 'master' into dev-vthreads-exec
2 parents c46490b + bae4c31 commit 03d6323

File tree

6 files changed

+36
-40
lines changed

6 files changed

+36
-40
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ Copyright © Rich Hickey and contributors
6565

6666
## Changelog
6767

68+
* Release 1.8.718-beta2 on 2025.03.10
69+
* [ASYNC-259](https://clojure.atlassian.net/browse/ASYNC-259) (CLJ) Implement `clojure.core.async.go-checking` with new executor pools
70+
* [ASYNC-260](https://clojure.atlassian.net/browse/ASYNC-260) (CLJ) Remove now unused property `clojure.core.async.pool-size`
71+
* [ASYNC-261](https://clojure.atlassian.net/browse/ASYNC-261) (CLJ) Put clojure.core.async/thread-macro-executor var back into place
6872
* Release 1.8.711-beta1 on 2025.02.19
6973
* [ASYNC-256](https://clojure.atlassian.net/browse/ASYNC-256) (CLJ) Add io-thread and System property clojure.core.async.executor-factory
7074
* [ASYNC-255](https://clojure.atlassian.net/browse/ASYNC-255) (CLJ) alts guards against put of nil message on entry

VERSION_TEMPLATE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.GENERATED_VERSION-beta1
1+
1.8.GENERATED_VERSION-beta2

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<groupId>org.clojure</groupId>
44
<artifactId>core.async</artifactId>
55
<!-- Don't set this manually! Call script/build/update_version -->
6-
<version>1.8.712-SNAPSHOT</version>
6+
<version>1.9.0-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<name>core.async</name>
99
<description>Facilities for async programming and communication in Clojure</description>

src/main/clojure/clojure/core/async.clj

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
(ns clojure.core.async
1010
"Facilities for async programming and communication.
1111
12-
go blocks are dispatched over an internal thread pool, which
13-
defaults to 8 threads. The size of this pool can be modified using
14-
the Java system property `clojure.core.async.pool-size`.
15-
1612
Set Java system property `clojure.core.async.go-checking` to true
1713
to validate go blocks do not invoke core.async blocking operations.
1814
Property is read once, at namespace load time. Recommended for use
@@ -58,9 +54,8 @@ return nil for unexpected contexts."
5854
)
5955
(:import [java.util.concurrent.atomic AtomicLong]
6056
[java.util.concurrent.locks Lock]
61-
[java.util.concurrent Executors Executor ThreadLocalRandom]
62-
[java.util Arrays ArrayList]
63-
[clojure.lang Var]))
57+
[java.util.concurrent ThreadLocalRandom]
58+
[java.util Arrays ArrayList]))
6459

6560
(alias 'core 'clojure.core)
6661

@@ -507,6 +502,8 @@ return nil for unexpected contexts."
507502
`(thread-call (^:once fn* [] ~@body) :io)
508503
(#'clojure.core.async.impl.go/go-impl &env body)))
509504

505+
(defonce ^:private thread-macro-executor nil)
506+
510507
(defn thread-call
511508
"Executes f in another thread, returning immediately to the calling
512509
thread. Returns a channel which will receive the result of calling

src/main/clojure/clojure/core/async/impl/dispatch.clj

+8-18
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88

99
(ns ^{:skip-wiki true}
1010
clojure.core.async.impl.dispatch
11-
(:require [clojure.core.async.impl.protocols :as impl])
1211
(:import [java.util.concurrent Executors ExecutorService ThreadFactory]))
1312

1413
(set! *warn-on-reflection* true)
1514

16-
(defonce ^:private in-dispatch (ThreadLocal.))
17-
1815
(defonce executor nil)
1916

2017
(defn counted-thread-factory
@@ -38,25 +35,18 @@
3835
(.setName (format name-format (swap! counter inc)))
3936
(.setDaemon daemon))))))))
4037

41-
(defonce
42-
^{:doc "Number of processors reported by the JVM"}
43-
processors (.availableProcessors (Runtime/getRuntime)))
44-
45-
(def ^:private pool-size
46-
"Value is set via clojure.core.async.pool-size system property; defaults to 8; uses a
47-
delay so property can be set from code after core.async namespace is loaded but before
48-
any use of the async thread pool."
49-
(delay (or (Long/getLong "clojure.core.async.pool-size") 8)))
38+
;; used only for implementing go-checking
39+
(def ^:private ^:dynamic *in-go-dispatch* false)
5040

5141
(defn in-dispatch-thread?
52-
"Returns true if the current thread is a go block dispatch pool thread"
42+
"Returns true if the current thread is used for go block dispatch"
5343
[]
54-
(boolean (.get ^ThreadLocal in-dispatch)))
44+
(boolean *in-go-dispatch*))
5545

5646
(defn check-blocking-in-dispatch
57-
"If the current thread is a dispatch pool thread, throw an exception"
47+
"If the current thread is being used for go block dispatch, throw an exception"
5848
[]
59-
(when (.get ^ThreadLocal in-dispatch)
49+
(when (in-dispatch-thread?)
6050
(throw (IllegalStateException. "Invalid blocking call in dispatch thread"))))
6151

6252
(defn ex-handler
@@ -68,8 +58,8 @@
6858
nil)
6959

7060
(defn- make-ctp-named
71-
[workflow]
72-
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true)))
61+
[workload]
62+
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workload) "-%d") true)))
7363

7464
(def virtual-threads-available?
7565
(try

src/main/clojure/clojure/core/async/impl/go.clj

+18-13
Original file line numberDiff line numberDiff line change
@@ -1041,18 +1041,23 @@
10411041
second
10421042
(emit-state-machine num-user-params user-transitions))))
10431043

1044+
(def ^:private go-checking (Boolean/getBoolean "clojure.core.async.go-checking"))
1045+
10441046
(defn go-impl
10451047
[env body]
1046-
(let [crossing-env (zipmap (keys env) (repeatedly gensym))]
1047-
`(let [c# (clojure.core.async/chan 1)
1048-
captured-bindings# (Var/getThreadBindingFrame)]
1049-
(dispatch/run
1050-
(^:once fn* []
1051-
(let [~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag))]) crossing-env)
1052-
f# ~(state-machine
1053-
`(do ~@body) 1 [crossing-env env] rt/async-custom-terminators)
1054-
state# (-> (f#)
1055-
(rt/aset-all! rt/USER-START-IDX c#
1056-
rt/BINDINGS-IDX captured-bindings#))]
1057-
(rt/run-state-machine-wrapped state#))))
1058-
c#)))
1048+
(let [crossing-env (zipmap (keys env) (repeatedly gensym))
1049+
run-body `(let [c# (clojure.core.async/chan 1)
1050+
captured-bindings# (Var/getThreadBindingFrame)]
1051+
(dispatch/run
1052+
(^:once fn* []
1053+
(let [~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag))]) crossing-env)
1054+
f# ~(state-machine
1055+
`(do ~@body) 1 [crossing-env env] rt/async-custom-terminators)
1056+
state# (-> (f#)
1057+
(rt/aset-all! rt/USER-START-IDX c#
1058+
rt/BINDINGS-IDX captured-bindings#))]
1059+
(rt/run-state-machine-wrapped state#))))
1060+
c#)]
1061+
(if go-checking
1062+
(list 'binding ['clojure.core.async.impl.dispatch/*in-go-dispatch* true] run-body)
1063+
run-body)))

0 commit comments

Comments
 (0)