# Bug in sleep() function - main thread work affecting sleep duration on running tasks

**URL:** <https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911>\
**Category:** General Usage\
**Tags:** question, multithreading, task, potential-bug\
**Created:** [July 21, 2023, 9:14pm UTC](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911 "2023-07-21T21:14:09Z")\
**Posts on this page:** 1\
**Showing post:** 47

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [August 29, 2023, 11:18pm UTC](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911/47 "2023-08-29T23:18:11Z")

</div>

### Update

Potentially, the following PR [might](https://github.com/JuliaLang/julia/pull/50880#issue-1845980888) be the answer to the bug report _generated_ by the current topic.

> This is slightly speculative, but it fixes [#50643](https://github.com/JuliaLang/julia/issues/50643) which is a start. But it hasn’t been tested under heavy contention of the uv lock.  
> It also currently uses the normal mutex but we probably need to switch to a lock that has some form of fairness (maybe [#50878](https://github.com/JuliaLang/julia/pull/50878) )

[Remove in threaded region and add a thread that runs the UV loop by gbaraldi · Pull Request #50880 · JuliaLang/julia (github.com)](https://github.com/JuliaLang/julia/pull/50880)

I didn’t have time to test if the above PR changes things - but I’ll do that soon and leave an update here.

Also, [here](https://discourse.julialang.org/t/julia-can-be-better-at-doing-web-a-benchmark/103300) is a (new) related topic that touches the issue raised by the current topic.

---

_[View the full topic](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911)._
