Experimenting with our runtime 263 Adding this to the top of our async_main function should work: ch10/b-rust-futures-examples/src/main. rs (async_main2) use tokio::runtime::Runtime; async fn async_main let rt = Runtime::new(). unwrap(); let _guard = rt. enter(); println!("Program starting"); let url = "http://127. 0. 0. 1:8080/600/Hello Async Await1"; ... Note Calling Runtime::new creates a multithreaded Tokio runtime, but Tokio also has a single-threaded runtime that you can create by using the runtime builder like this: Builder::new_ current_thread(). enable_all(). build(). unwrap(). If you do that, you end up with a peculiar problem: a deadlock. The reason for that is interesting and one that you should know about. Tokio's single-threaded runtime uses only the thread it's called on for both the executor and the reactor. This is very similar to what we did in the first version of our runtime in Chapter 8. We used the Poll instance to park our executor directly. When both our reactor and executor execute on the same thread, they must have the same mechanism to park themselves and wait for new events, which means there will be a tight coupling between them. When handling an event, the reactor has to wake up first to call Waker::wake, but the executor is the last one to park the thread. If the executor parked itself by calling thread::park (like we do), the reactor is parked as well and will never wake up since they're running on the same thread. The only way for this to work is that the executor parks on something shared with the reactor (like we did with Poll ). Since we're not tightly integrated with Tokio, all we get is a deadlock. Now, if we try to run our program once more, we get the following output: Program starting main: 1 pending tasks. Sleep until notified. main: 1 pending tasks. Sleep until notified. main: 1 pending tasks. Sleep until notified. Hello Async Await1 main: 1 pending tasks. Sleep until notified. main: 1 pending tasks. Sleep until notified. main: 1 pending tasks. Sleep until notified. Hello Async Await2 main: All tasks are finished