Skip to content

Commit 16383f2

Browse files
authored
Fix access_threaded in the forthcoming interactive threadpool world (#972)
Fixes #970. The issue here is that our `access_threaded` function, and thread-specific arrays, all relied on `Threads.nthreads()`, which by default only returns the number of threads in the `:default` threadpool. In the new world where the `:interactive` threadpool exists, there can also be threads there. There is a new function `Threads.maxthreadid()` which helpfully tells us the max id of any thread, regardless of threadpool. So the proposed fix here is that if that function is defined, use that, otherwise fallback to `Threads.nthreads()`.
1 parent 5603a36 commit 16383f2

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/Parsers.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,12 @@ const unhex = Int8[
351351
function __init__()
352352
# FIXME Consider turing off `PCRE.UTF` in `Regex.compile_options`
353353
# https://github.com/JuliaLang/julia/pull/26731#issuecomment-380676770
354-
resize!(empty!(status_line_regex), Threads.nthreads())
355-
resize!(empty!(request_line_regex), Threads.nthreads())
356-
resize!(empty!(header_field_regex), Threads.nthreads())
357-
resize!(empty!(obs_fold_header_field_regex), Threads.nthreads())
358-
resize!(empty!(empty_header_field_regex), Threads.nthreads())
354+
nt = isdefined(Base.Threads, :maxthreadid) ? Threads.maxthreadid() : Threads.nthreads()
355+
resize!(empty!(status_line_regex), nt)
356+
resize!(empty!(request_line_regex), nt)
357+
resize!(empty!(header_field_regex), nt)
358+
resize!(empty!(obs_fold_header_field_regex), nt)
359+
resize!(empty!(empty_header_field_regex), nt)
359360
return
360361
end
361362

src/Servers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Accepts new tcp connections and spawns async tasks to handle them."
363363
function listenloop(f, listener, conns, tcpisvalid,
364364
max_connections, readtimeout, access_log, ready_to_accept, verbose)
365365
sem = Base.Semaphore(max_connections)
366-
verbose >= 0 && @infov 1 "Listening on: $(listener.hostname):$(listener.hostport)"
366+
verbose >= 0 && @infov 1 "Listening on: $(listener.hostname):$(listener.hostport), thread id: $(Threads.threadid())"
367367
notify(ready_to_accept)
368368
while isopen(listener)
369369
try

src/parsemultipart.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ function parse_multipart_form(msg::Message)::Union{Vector{Multipart}, Nothing}
246246
end
247247

248248
function __init__()
249-
resize!(empty!(content_disposition_regex), Threads.nthreads())
250-
resize!(empty!(content_disposition_flag_regex), Threads.nthreads())
251-
resize!(empty!(content_disposition_pair_regex), Threads.nthreads())
252-
resize!(empty!(content_type_regex), Threads.nthreads())
249+
nt = isdefined(Base.Threads, :maxthreadid) ? Threads.maxthreadid() : Threads.nthreads()
250+
resize!(empty!(content_disposition_regex), nt)
251+
resize!(empty!(content_disposition_flag_regex), nt)
252+
resize!(empty!(content_disposition_pair_regex), nt)
253+
resize!(empty!(content_type_regex), nt)
253254
return
254255
end
255256

0 commit comments

Comments
 (0)