Building an AsyncIO executor for the 3DS

https://lobste.rs/rss Hits: 26
Summary

Building an AsyncIO executor for the 3DS (pt 1!) 16 May, 2026 the Nintendo 3DS is a very fun device to write homebrew for, but one thing about it can be annoying: its multitasking is non-preemptive! in this little series, we'll be building an asyncio executor for the 3ds. in this first part: why and what is async, anyways? what?the way threads and processes usually work in operating systems is through pre-emption: a thread can only run for a little bit of time before it gets temporarily paused so the next thread in line can run. so, if you spawn a super intensive long-running thread, it won't be able to hog the entire CPU, as the OS will take over and make sure everyone else can get some CPU time. but the 3ds is cooperativethis means that threads are only paused when they ask to be. so if our super intensive long-running thread never gives up the CPU, nothing else will be able to run! of course, we can just be careful and make sure it doesn't, but it's really easy to forget. it'd be convenient if there was a way to model this problem in the way we write our code... straight up awaiting itasync programming is just such a model! in an async program, we model each bit of work as a task. a task is not supposed to hog the CPU: it should do a little bit of work, then go to sleep while waiting for something to happen (e.g, a TCP packet to come in), then do a little more work. a thing we can wait on is called a Future. none of this is impossible to do without async: it just makes it very explicit. this is specially important in the case of the 3ds, where platform behaviour is... sometimes unpredictable in terms of what will cause a task to yield or not. // in a normal program, it can be hard to know whether this will put our thread to sleep or not... socket.read(); // but in async, it's explicit that it will make our task wait! socket.read().await; the magic .await indicates that we want our task to sleep until socket.read() (which is a Future) is complete. okay, but how do...

First seen: 2026-05-26 15:36

Last seen: 2026-05-27 16:55