This is another post about programming, which I almost never write about.Click here to jump straight to trying this thing out for yourself.In my previous post on Threads, I made an offhand comparison:Threads are just emulator save states, coupled with a condition upon which they will be resumed.At the time, I thought this a pretty okay analogy — but I couldn’t stop thinking about it. I’ve been turning it around in my mind for a while. I think it has serious untapped potential as a pedagogical tool. So I added multithreading to Super Mario Bros. for the NES.No buried ledes here. I should explain myself. What you just watched happens to be a multithreaded NES emulation, with Super Mario Bros. as the threads.There are three “threads” running, each a distinct instance of the game. Every so often, the emulator switches “threads”, swapping to a different instance of the game. Each “thread” is assigned a different color palette, which we apply when we resume said thread. This is why the colors are constantly changing around in the video.When World 1-1 starts, the “multithreading” begins. Specifically, my script creates three save states, each representing the current state of the game. Then I create three threads, and give them their respective save state to hold on to.Then I start the thread scheduler.The thread scheduler’s job is simple:This covers what you see for the first bit of the video: each thread starts at the same time (the loading screen for World 1-1), with different “games” being swapped in every so often. Essentially, three different games of Mario Bros. are being played “at the same time”, but only one is actually active at any given time.This image shows the full World 1-1 map, with color-coded areas indicating various features explained below. I recommend clicking to expand this image.Time slicing is cool — we’re running three “concurrent” games of Mario! — but that’s far from the only threading concept demonstrated here.I’ve set up the game world in such...
First seen: 2025-05-28 21:02
Last seen: 2025-05-29 16:06