Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make thread 1 interactive when there is an interactive pool, so it can run the event loop #49094

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

JeffBezanson
Copy link
Member

There is a major problem preventing interactive threads from working well, which is that outside an @threads region thread 1 is still the only one allowed to run the event loop. Responding to events is kind of the whole deal with interactive threads, so they need to be able to enter the event loop. We can't fully fix this until _threadedregion is finally removed. So to make interactive threads work in the meantime, this PR proposes making the interactive pool the first one, so thread 1 is interactive. For code like the following:

@spawn long_compute()
@spawn :interactive display_progress()

this PR takes it from not working to working.

@JeffBezanson JeffBezanson added multithreading Base.Threads and related functionality backport 1.9 Change should be backported to release-1.9 labels Mar 22, 2023
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add an API at the same time for people to enumerate all worker thread ids (to keep the @threads macro working correctly)?

base/threadingconstructs.jl Outdated Show resolved Hide resolved
src/threading.c Outdated Show resolved Hide resolved
@kpamnany
Copy link
Contributor

Thanks for this fix! I've been meaning to dig into why our interactive thread isn't being very interactive...

@JeffBezanson
Copy link
Member Author

Ok I have implemented all of the above. I wasn't sure we wanted to always have 2 threadpools but I guess there is no harm. The new function is provisionally named threadpoolids.

@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Mar 22, 2023
@KristofferC KristofferC mentioned this pull request Mar 24, 2023
52 tasks
@IanButterworth IanButterworth removed the merge me PR is reviewed. Merge when all tests are passing label Mar 31, 2023
@IanButterworth
Copy link
Member

Removing merge me given @kpamnany's question #49094 (comment)

@KristofferC KristofferC mentioned this pull request Apr 9, 2023
26 tasks
@KristofferC
Copy link
Member

Bump

@JeffBezanson JeffBezanson added the merge me PR is reviewed. Merge when all tests are passing label Apr 12, 2023
@KristofferC KristofferC merged commit 9ed4087 into master Apr 13, 2023
@KristofferC KristofferC deleted the jb/interactive0 branch April 13, 2023 13:04
KristofferC pushed a commit that referenced this pull request Apr 13, 2023
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Apr 19, 2023
Xnartharax pushed a commit to Xnartharax/julia that referenced this pull request Apr 19, 2023
@KristofferC KristofferC removed the backport 1.9 Change should be backported to release-1.9 label Apr 25, 2023
vtjnash pushed a commit that referenced this pull request Jan 31, 2024
Since #49094, the docstring of
`nthreads` has been incorrect. It currently states that

> The threads in default have id numbers `1:nthreads(:default)`.

whereas that is no longer true:
```julia
julia> filter(i -> Threads.threadpool(i) == :interactive, 1:Threads.maxthreadid())
3-element Vector{Int64}:
 1
 2
 3

julia> filter(i -> Threads.threadpool(i) == :default, 1:Threads.maxthreadid())
6-element Vector{Int64}:
 4
 5
 6
 7
 8
 9
```
KristofferC pushed a commit that referenced this pull request Feb 6, 2024
Since #49094, the docstring of
`nthreads` has been incorrect. It currently states that

> The threads in default have id numbers `1:nthreads(:default)`.

whereas that is no longer true:
```julia
julia> filter(i -> Threads.threadpool(i) == :interactive, 1:Threads.maxthreadid())
3-element Vector{Int64}:
 1
 2
 3

julia> filter(i -> Threads.threadpool(i) == :default, 1:Threads.maxthreadid())
6-element Vector{Int64}:
 4
 5
 6
 7
 8
 9
```

(cherry picked from commit 95ae27f)
Drvi pushed a commit to RelationalAI/julia that referenced this pull request Jun 7, 2024
Since JuliaLang#49094, the docstring of
`nthreads` has been incorrect. It currently states that

> The threads in default have id numbers `1:nthreads(:default)`.

whereas that is no longer true:
```julia
julia> filter(i -> Threads.threadpool(i) == :interactive, 1:Threads.maxthreadid())
3-element Vector{Int64}:
 1
 2
 3

julia> filter(i -> Threads.threadpool(i) == :default, 1:Threads.maxthreadid())
6-element Vector{Int64}:
 4
 5
 6
 7
 8
 9
```

(cherry picked from commit 95ae27f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants