The developer of Pumpkin OS (which we talked about before), a port of the Palm OS to x86-64, has written a very interesting post about dealing with multi-threading. Pumpkin OS is multi-threaded from the start, but several parts of the operating system rely on old parts of Palm OS that were never meant to be multi-threaded – such as the M68K emulator used to run Palm OS applications written for that architecture.
The solution I came up with uses something called thread local storage. Each thread has access to a private memory region that the main thread can setup in advance. When a deeply nested function needs to access global state, instead of using a global variable, it gets a pointer to its local storage. Each emulated M68K thread writes to its own M68K state, not interfering with another thread. And no function prototype needs to change. The first step was to identify all global variables used by the M68K emulator, which were surprisingly few.
I’m so excited about this project.
What is the reason for this project (other than the totally valid ‘because I want to’). Is it for some kind of legacy app support or just a labour of love?
What are retro emulator used for ?
Kochise,
Let’s be honest, that’s a labor of love too. I’ll go duck behind the bar now. ๐
Actually I love to work on these kinds of projects. If you are doing it for yourself, I’d say go for it, but if you are doing it to change the world, let’s just say it’s a long shot. When I worked on operating systems I never found a way to make it profitable, it’s high cost low payout. Companies don’t really want to pay for it when off the shelf operating systems are cheaper and more accessible in every way. Once you get a job you really have to start prioritizing things including hobbies. Some people do art, others do operating systems, others just drink, maybe some do all three, haha. I don’t judge how people want to spend their time, I just hope they’re happy doing it.
Playing old games that otherwise would be lost to time. Seems like you read something in my comment that wasn’t there.
Fast palm apps! Seriously, I would love to get this up and running and try my palm app from 2002 that was so dog slow we just abandoned support for palmos io was too slow. I can’t remember of that was just the file system, internal storage or the port speed. The crappiest windows ce device would take 2 minutes to perform the operation, while the best, fastest palm took 30 min. Our instructions recommended a fresh power on of the windows ce, due to memory leaks in those things but they were easy to program and great to work with other than that.
It is always about the journey, isn’t it ?
In the course of developing PumpkinOS, I came across so many topics, including but not limited to:
graphics programming;
multi-thread programming;
heap allocation strategies;
ARM architecture;
emulation;
PalmOS internals (really ๐
pmig96,
Those are all fun topics!
With multithreading, intercore locking/syncrhonization is a performance killer. So whenever I’m doing more low level development I get into the habit of avoiding locking whenever possible, especially those that would cause a context switch to the operating system. I was able to beat libc’s default memory allocator for multithreaded programs by giving each thread it’s own “heap” (using the term loosely) and managing it with thread local storage. This local heap was lock-free. It was only when the local thread heap was consumed that it would replenish through a global alloocator. I used compare and swap atomics to maintain global lists as I recall. I also had to handle allocating in one thread and freeing from another (needed in workflows where one thread is a producer and another is a consumer).
I have so much fun doing low level coding, But the vast majority of companies only want high level development or worse: customizing off the shelf solutions. That kills creativity IMHO. Oh well.
Because we are rapidly reaching a digital dark age where the past is erased because nobody can run anything more than a few years old? I hate to break the news to ya friend but the era of the desktop is coming to an end and more and more young people are growing up knowing nothing but tablets and smartphones and the software that runs on those devices? Is Disappearing faster and faster as new versions won’t run older software and the appstores are purged of older titles.
So I’m glad someone is making a way to run these older mobile OSes as i can easily see a day when anyone can fire up DOSbox and play every PC game from the 1980s but a huge chunk of the last 20 years is just gone forever as nobody will have emulators for these old mobile OSes or repos of the software they ran.