# Non-static, Non-Send Tokio Spawn Blocking with &self and Scoped Threads

**URL:** <https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836>\
**Category:** help\
**Created:** [June 19, 2026, 9:53pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836 "2026-06-19T21:53:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![naftulikay](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/naftulikay/32/6929_2.png) [@naftulikay](https://users.rust-lang.org/u/naftulikay)\
**Post date:** [June 19, 2026, 9:53pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/1 "2026-06-19T21:53:59Z")

</div>

I have a function like this:

```rust
pub async fn work_async(&self) -> Result<(), Error> {

}

```

I also have a synchronous implementation of this that uses `std::thread::scope` to spawn threads in a way where I don't have to deal with `'static` lifetimes or `Send`:

```rust
pub fn work_threaded(&self) -> Result<(), Error> {
    std::thread::scope(|s| {
        let a = s.spawn(|| self.work_task_a());
        let b = s.spawn(|| self.work_task_b());

        let _a = a.join().unwrap();
        let _b = b.join().unwrap();

        Ok(())
   }).unwrap()
}

```

My constraints here are:

1. I cannot make self `Send` or `'static`.
2. My work tasks are black boxes, they cannot be made into async functions.
3. My work tasks absolutely block the calling thread
4. The work done by both tasks should proceed concurrently and not serially, as each of these operations take around 10 seconds to complete and I can't wait 20 seconds.
5. I want to not block in my async implementation so that other work on the executors can continue.
6. My work tasks absolutely need `&self`, but I could make them `&mut self` if need be.

I'm trying to look into `tokio-scoped` but I'm still having trouble with lifetimes.

So I essentially have a future which must live as long as `&self` but which must be able to spawn (scoped probably) threads.

Is there a way for me to use `Pin` to somehow get around the lifetime issues? I essentially need to go from a future to `tokio::task::spawn_blocking` into `std::thread::scope` and express that this future has the same lifetime as `&self` so as to ensure everything lives long enough without going to `'static` or having to make things `Send`.

Is this at all possible?

---

<div class="post-metadata">

**Author:** ![R081n](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/r081n/32/40958_2.png) [@R081n](https://users.rust-lang.org/u/R081n)\
**Post date:** [June 19, 2026, 10:57pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/2 "2026-06-19T22:57:56Z")

</div>

You could use [block\_in\_place in tokio::task - Rust](https://docs.rs/tokio/latest/tokio/task/fn.block_in_place.html)

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [June 19, 2026, 11:25pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/3 "2026-06-19T23:25:26Z")

</div>

What you’ve hit here is [the scoped task trilemma](https://without.boats/blog/the-scoped-task-trilemma/):

> Any sound API can only provide at most two of the following three desirable properties:
> 
> 1. **Concurrency:** Child tasks proceed concurrently with the parent.
> 2. **Parallelizability:** Child tasks can be made to proceed in parallel with the parent.
> 3. **Borrowing:** Child tasks can borrow data from the parent without synchronization.

You must give up on having one of these properties. Presuming that the most important things are async API and the speedup gained by executing your blocking code in parallel, you must give up on borrowing: this means that you must arrange so that the code managing the tasks (`work_threaded()` or its caller) must _own_ all of the data it needs to use, but the tasks can still borrow from that manager. Once you have arranged this, you can use tokio’s `spawn_blocking()` to run `work_threaded()`.

(`block_in_place()` solves this problem by giving up on concurrency; `block_in_place()` will cause any code that uses `join()` or `select!()` on your future that uses `block_in_place()` to stop running its other branches until the blocking ends. All it achieves is preventing _other Tokio tasks_ from being blocked by your blocking.)

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [June 19, 2026, 11:27pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/4 "2026-06-19T23:27:53Z")

</div>

> [@naftulikay](#):
>
> ... in a way where I don't have to deal with `'static` lifetimes or `Send`:

the scoped thread api removes the `'static` limitation, but you always need `Send` for multi-threaded work. you maybe thinking about something else.

> [@naftulikay](#):
>
> 1. I want to not block in my async implementation so that other work on the executors can continue.

the problem with async scoped task spawing is what's called leakpocalypse: you cannot rely on destructors being run for safety invariants.

so what you end is either:

- the api is safe but the thread must be blocked, like `tokio_scoped::scoped()`, or:

- you don't block the caller but the api is unsound, or at least very `unsafe`, like many other attempts for the problem.

if your tasks are io bound, you may use the "join" combinator to achieve some concurrency (but cpu work is interleved/multiplexed, NOT in parallel).

---

<div class="post-metadata">

**Author:** ![naftulikay](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/naftulikay/32/6929_2.png) [@naftulikay](https://users.rust-lang.org/u/naftulikay)\
**Post date:** [June 24, 2026, 4:59pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/5 "2026-06-24T16:59:36Z")

</div>

From the docs:

> Runs the provided blocking function on the current thread without blocking the executor.  
> ...  
> Calling this function informs the executor that the currently executing task is about to block the thread, so the executor is able to hand off any other tasks it has to a new worker thread before that happens.

And from your answer:

> [@kpreid](#):
>
> (`block_in_place()` solves this problem by giving up on concurrency; `block_in_place()` will cause any code that uses `join()` or `select!()` on your future that uses `block_in_place()` to stop running its other branches until the blocking ends. All it achieves is preventing _other Tokio tasks_ from being blocked by your blocking.)

So in my case I ultimately decided that `block_in_place` was sufficient for my needs, as the synchronous threaded code that it calls is essentially a `flush` or `shutdown` operation that mainly needs to be called at the very end of a program's lifecycle.

I have no futures _whatsoever_ in my call to `block_in_place`, and it seems okay to me that due to the purpose of these APIs that the likelihood of `select!` or `join!` happening on the same worker is low and it is acceptable that these can be starved during the flush/shutdown until that call returns.

(by the way @kpreid thanks for all that you do in the Rust community! you've helped me personally countless times and I'm sure the same is true for many others. thank you!)

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [June 24, 2026, 7:34pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/6 "2026-06-24T19:34:04Z")

</div>

> [@naftulikay](#):
>
> I have no futures _whatsoever_ in my call to `block_in_place`, and it seems okay to me that due to the purpose of these APIs that the likelihood of `select!` or `join!` happening on the same worker is low and it is acceptable that these can be starved during the flush/shutdown until that call returns.

I think you misunderstand what the constraint for correct use of `block_in_place()` is. It's not about what you do in `block_in_place()`; it's about what the _caller_ of your async function does. If the caller uses `select!()` or `join()` on your function and another function, they will be blocked.

That is, if the control flow is

```rust
tokio:spawn(async {
    join(
        your_function_that_calls_block_in_place(),
        other_function(),
    ).await
})

```

then `other_function()`s execution will be blocked. This is why `block_in_place()` is hazardous to use: it _doesn't compose_ like a `Future` should, so callers of it have to be restricted to avoid stalls/deadlocks.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 22, 2026, 7:34pm UTC](https://users.rust-lang.org/t/non-static-non-send-tokio-spawn-blocking-with-self-and-scoped-threads/140836/7 "2026-09-22T19:34:43Z")

</div>

Closed on September 22, 2026, 7:34pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
