Thread Safety with Mutexes in Ruby Discussion
In a Rails application that does standard CRUD for the most part, what would be a good use case for something like this? In the ferrum_pdf example you gave, it looks like you want to ensure there's one and only one browser instance running; is that something that could be addressed by launching the browser at initialization time instead of allowing competing code to start it (if I understood the example correctly)?
I'm very interested in more content that dives deeper into Ruby threads/ractors/performance/etc; one of the constant complaints I hear about Ruby is that it's "slow", even though it's plenty fast enough for web development. But if Ruby ever wants to compete in the space of something like Python in the AI or data science fields, it needs to be as fast as possible outside the web development arena. I just saw the Stack Overflow survey results, and Python is one of the top languages mostly because it's used heavily in AI and data science (from my understanding) and Ruby sits way down the list because it seems it's relegated mostly to web app development.
In a typical Rails CRUD app, you probably wouldn’t need a mutex/singleton pattern for most objects — database connections, mailers, and similar resources already have pooling and lifecycle management handled for you by Rails and its dependencies.
You can definitely initialize the browser right at app startup, but only if the app doesn't run multiple processes or threads in parallel.