💾 Archived View for freeshell.de › gemlog › 2024-01-01_Tiny_threads_again.gmi captured on 2024-05-26 at 14:45:51. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-02-05)
-=-=-=-=-=-=-
I want a tune to play while my Thumby game is doing something else.
Previously, I tried a new thread for every tune: didn't quite work
Plan B is a function list to which I append a tune function when I'd like it to play. Another thread notices that the list grew, and plays the tune. It seems that appending and reading lists on different threads is safe. I hacked up a proof of concept for this, and it works. Naturally, further issues arise.
What are those threads doing? I need a log. I can't write to the screen because it's ridiculously small and it's needed for the game. So the log is a file. A mutex means only one thread uses the file at once. Seems simple.
We start off OK, but after a while both threads stop logging and the display stops updating. I'm fairly confident that the threads can't deadlock, but pick any combination of:
If I comment out the file logging, all is well.
I note that the documentation for the _thread module says:
This module is highly experimental and its API is not yet fully settled and not yet described in this documentation.
As much as I might laugh in the face of danger, seems like I've dug myself a hole.
The second thread does play tunes and doesn't need to write to a file. So I have what I wanted, as long as nothing unexpected happens and I need a log. What could possibly go wrong?
Next step: apply this stuff to the actual game, not the quick hack...