Skip to content

Mention Base.Lockable in "multi-threading.md" #58107

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KronosTheLate
Copy link
Contributor

When I originally learned about multithreading and locks (and ended up rewriting [https://docs.julialang.org/en/v1/manual/multi-threading/#man-using-locks](Using locks to avoid data-races)), I was puzzled to find that the association of a lock and a value was the mental task of the programmer, and not the programmatic task of the program. I made that explicit in that section of the manual, writing the following:

Note that the link between a lock and a variable is made by the programmer, and not the program.

I was therefore very happy to see Base.Lockable introduced in Julia 1.11. What was missing, was any mention of it in the relevant section of the manual.

This PR adds a subsection under locks (So a forth level of headings, not sure if that is fine), showcasing and reccomending the use of Base.Lockable. I have made heavy use of comments in the example, which breaks with the general style, but adds valuable interpretation along the way. I am very open restructuring that part in particular.

When I originally learnt about multithreading and locks (and ended up rewriting [https://docs.julialang.org/en/v1/manual/multi-threading/#man-using-locks](Using locks to avoid data-races)), I was puzzled to find that the association of a lock and a value was the mental task of the programmer, and not the programmatic task of the program.

I was therefore very happy to see Base.Lockable introduced in Julia 1.11. What was missing, was any mention of it in the relevant section of the manual.

This PR adds a subsection under locks (So a forth level of headings, not sure if that is fine), showcasing and reccomending the use of Base.Lockable. I have made heavy use of comments in the example, which breaks with the general style, but adds valuable interpretation along the way. I am very open restructuring that part in particular.
@nsajko nsajko added docs This change adds or pertains to documentation parallelism Parallel or distributed computation multithreading Base.Threads and related functionality labels Apr 14, 2025
@nsajko
Copy link
Contributor

nsajko commented Apr 14, 2025

how far back can this be backported?

@KronosTheLate
Copy link
Contributor Author

I am almost certain that Lockable was introduced in 1.11.

@KronosTheLate
Copy link
Contributor Author

Can confirm that Base.Lockable is not defined in 1.10, but is in 1.11.

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.4 (2025-03-10)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> Base.Lockable
Base.Lockable

julia>

󰍲 dennis.bal  ~   v3.12.10   08:09 
 julia +1.10
ERROR: `1.10` is not installed. Please run `juliaup add 1.10` to install channel or version.

󰍲 dennis.bal  ~   v3.12.10   08:09 
 juliaup add 1.10
Checking for new Julia versions
Installing Julia 1.10.9+0.x64.w64.mingw32

󰍲 dennis.bal  ~   v3.12.10   08:10 
 julia +1.10
Precompiling OhMyREPL finished.
  8 dependencies successfully precompiled in 17 seconds
[ Info: OhMyREPL loaded
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.9 (2025-03-10)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> Base.Lockable
ERROR: UndefVarError: `Lockable` not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:31
 [2] top-level scope
   @ REPL[1]:1

@KronosTheLate
Copy link
Contributor Author

Is this PR waiting for anything in particular?



```julia-repl
julia> my_array = []; # Simple empty array
Copy link
Member

Choose a reason for hiding this comment

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

Some comments about this code block:

  • I think it is overcommenting a bit. There is not really a need to comment on creating an empty array.
  • The comments become quite long on a single line, which will require horizontal scrolling to read on the website.

I'd take some inspiration of how the section below is written, ideally the text before the code should be enough to understand the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation multithreading Base.Threads and related functionality parallelism Parallel or distributed computation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants