Skip to content

The "quick fix with caveats" example is not correct #136

@KristofferC

Description

@KristofferC

The example in https://juliafolds2.github.io/OhMyThreads.jl/stable/literate/tls/tls/#The-quick-fix-(with-caveats) assumes that threadid() will be in the range 1:nthreads() which is not true in the presence of e.g. interactive threads. Running the example on master where there is an interactive thread by default gives:

  nested task error: BoundsError: attempt to access 1-element Vector{Matrix{Float64}} at index [2]
    Stacktrace:
      [1] throw_boundserror(A::Vector{Matrix{Float64}}, I::Tuple{Int64})
        @ Base ./essentials.jl:15
      [2] getindex
        @ ./essentials.jl:917 [inlined]
      [3] (::var"#matmulsums_perthread_static##2#matmulsums_perthread_static##3"{})(A::Matrix{…}, B::Matrix{…})
        @ Main ./REPL[3]:5
      [4] #Generator##0
        @ ./generator.jl:37 [inlined]

Some further examples:

julia> Threads.nthreads()
1

julia> Threads.maxthreadid()
2

julia> Threads.@threads for i = 1:10
               @show Threads.threadid()    
           end
Threads.threadid() = 2
Threads.threadid() = 2
Threads.threadid() = 2

This example could be changed to use maxthreadid which might waste some space or perhaps be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions