# What is a RecursiveLock?

**URL:** <https://discourse.julialang.org/t/what-is-a-recursivelock/71897>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [November 22, 2021, 3:29pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897 "2021-11-22T15:29:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 22, 2021, 3:29pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/1 "2021-11-22T15:29:44Z")

</div>

Hi all 🙂

I just stumbled over that:

[https://github.com/JuliaLang/julia/blob/ae336abc0ed7e63ab933d0073df28c51e981d8fc/base/condition.jl#L37](https://github.com/JuliaLang/julia/blob/ae336abc0ed7e63ab933d0073df28c51e981d8fc/base/condition.jl#L37)

Where is the `RecursiveLock` defined?

Cheers

---

<div class="post-metadata">

**Author:** ![woclass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woclass/32/212699_2.png) [@woclass](https://discourse.julialang.org/u/woclass)\
**Post date:** [November 22, 2021, 4:23pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/2 "2021-11-22T16:23:47Z")

</div>

> [@Impressium](#):
>
> Where is the `RecursiveLock` defined?

Maybe it’a typo, means `ReentrantLock`.

> In [computer science](https://en.wikipedia.org/wiki/Computer_science), the **reentrant mutex** ( **recursive mutex** , **recursive lock** ) is a particular type of [mutual exclusion](https://en.wikipedia.org/wiki/Mutual_exclusion) (mutex) device that may be locked multiple times by the same [process/thread](https://en.wikipedia.org/wiki/Thread_(computing)), without causing a [deadlock](https://en.wikipedia.org/wiki/Deadlock).

> <https://github.com/JuliaLang/julia/pull/30061>
>
> This extends Condition and RecursiveLock to assert that they may only be used in… the single-threaded case (co-operatively scheduled), and then adds thread-safe versions of the same (ConditionMT and RecursiveLockMT). Additionally, the constructor for \`ConditionMT\` lets you pass in an existing \`RecursiveLockMT\` to allow having multiple notifications off of a single lock.
> 
> Unlike the existing thread-safe primitives (Threads.AsyncCondition, Threads.SpinLock, Threads.Mutex), these new types integrate with the Task system also, and thus should typically be preferred to those for user code. Unlike the existing task-only primitives, these work in all situations, but require the user to write explicit lock code annotating the protected code regions.
> 
> In version 2.0, we can consider switching the default for \`Condition\` from \`ConditionST\` to \`ConditionMT\`, but that would be a breaking change. (ConditionMT requires the user to hold a lock before calling \`wait\`, while that lock is currently implicit in Condition under the assumption of cooperative tasking—as explicitly represented in this PR by the \`NotALock\` type.)
> 
> Implement and close #30026

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 22, 2021, 4:26pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/3 "2021-11-22T16:26:38Z")

</div>

Should we change it?

---

<div class="post-metadata">

**Author:** ![woclass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woclass/32/212699_2.png) [@woclass](https://discourse.julialang.org/u/woclass)\
**Post date:** [November 22, 2021, 4:31pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/4 "2021-11-22T16:31:18Z")

</div>

I think you can open a pr to fix it and ask `vtjnash` to review.

At least, we should remove this invalid reference.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 22, 2021, 4:35pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/5 "2021-11-22T16:35:53Z")

</div>

Can you walk me through it? Do I need to create a new branch for that?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 22, 2021, 4:38pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/6 "2021-11-22T16:38:22Z")

</div>

TLDR is go here [https://github.com/JuliaLang/julia/blob/master/base/condition.jl](https://github.com/JuliaLang/julia/blob/master/base/condition.jl), click edit (pencil icon in top right), make the changes, and github should automatically make a fork for you.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 22, 2021, 4:42pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/7 "2021-11-22T16:42:41Z")

</div>

That was easy 🙂  
[https://github.com/JuliaLang/julia/pull/43192](https://github.com/JuliaLang/julia/pull/43192)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 22, 2021, 4:50pm UTC](https://discourse.julialang.org/t/what-is-a-recursivelock/71897/8 "2021-11-22T16:50:14Z")

</div>

Congrats!
