Skip to content

Commit 0cde249

Browse files
committed
Added runtime check for odd condition where user may target vthreads but then run on a non-vthreads jvm.
1 parent b9ea780 commit 0cde249

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ use vthreads in io-thread when available
515515
completed"
516516
[& body]
517517
(if (or (dispatch/aot-vthreads?) (dispatch/runtime-vthreads?))
518-
`(thread-call (^:once fn* [] ~@body) :io)
518+
`(if (and (= dispatch/compiled-vthreads-flag "target") (not (dispatch/runtime-vthreads?)))
519+
(throw (ex-info "Code compiled to target virtual threads, but is running on a JVM without vthread support."
520+
{:compiled-vthreads-flag dispatch/compiled-vthreads-flag
521+
:runtime-jvm-version (System/getProperty "java.version")}))
522+
(thread-call (^:once fn* [] ~@body) :io))
519523
((find-var 'clojure.core.async.impl.go/go-impl) &env body)))
520524

521525
(defonce ^:private thread-macro-executor nil)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@
8585
[]
8686
(System/getProperty "clojure.core.async.vthreads"))
8787

88+
(def compiled-vthreads-flag (vthreads-directive))
89+
8890
(defn aot-vthreads? []
8991
(and clojure.core/*compile-files*
9092
(= (vthreads-directive) "target")))
9193

92-
(defn runtime-vthreads? []
93-
(and (not clojure.core/*compile-files*)
94-
(not= (vthreads-directive) "avoid")
95-
@virtual-threads-available?))
94+
(def runtime-vthreads?
95+
(memoize
96+
(fn []
97+
(and (not clojure.core/*compile-files*)
98+
(not= (vthreads-directive) "avoid")
99+
@virtual-threads-available?))))
96100

97101
(defn- make-io-executor
98102
[]

0 commit comments

Comments
 (0)