# Mark a thread as more important than other threads (with respect to \`sleep\`)?

**URL:** https://discourse.julialang.org/t/mark-a-thread-as-more-important-than-other-threads-with-respect-to-sleep/28350
**Category:** General Usage
**Tags:** multithreading
**Created:** [September 3, 2019, 9:05pm UTC](https://discourse.julialang.org/t/mark-a-thread-as-more-important-than-other-threads-with-respect-to-sleep/28350 "2019-09-03T21:05:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [September 3, 2019, 9:05pm UTC](https://discourse.julialang.org/t/mark-a-thread-as-more-important-than-other-threads-with-respect-to-sleep/28350/1 "2019-09-03T21:05:00Z")

</div>

I started using the following code pattern:

```julia
my_tasks = []
for i in my_inputs
    task = @spawn my_function(i)
    push!(my_tasks, task)
end

while !all(istaskdone.(my_tasks))
    sleep(1)
    println("some progress message about the tasks")
end

```

However, if I spawn a lot of tasks, the main thread does not resume from the `sleep` call, instead it waits for most of the other spawned tasks to finish.

What would be the “proper” way to ensure that the main thread is of sufficiently high priority to continue executing no matter how many tasks were spawned.

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [September 4, 2019, 12:09pm UTC](https://discourse.julialang.org/t/mark-a-thread-as-more-important-than-other-threads-with-respect-to-sleep/28350/2 "2019-09-04T12:09:02Z")

</div>

You could use some magic to keep a single PARTR thread isolated for just your main task. Doing `ccall( :jl_set_task_tid, ...)` appropriately and then setting `task.sticky = true` for each task would do it, although you’d end up needing to manually schedule each task (making the PARTR scheduler mostly useless). This is the case because you can only say what thread a task _must_ run on, but you can’t say which thread a task _cannot_ run on, so if you didn’t manually schedule the non-main tasks, they’d still get placed on the main task’s thread.
