0

I'm trying to learn how to use the Allegro 5 game programming library. I'm wondering how I can find out which library functions are threadsafe. I understand how to use mutexes to ensure safety in my own code, but the amount that I may need to use them when calling Allegro's own functions is unclear to me.

The Allegro FAQ says it is threadsafe, and links to this thread. However, that thread isn't very helpful because the "really good article" linked in the first comment is a dead link, and the conclusion of the commentors seems to be "Allegro is mostly threadsafe", with no indication about which parts may not be.

Charlim
  • 521
  • 4
  • 12
  • The rule of thumb is: nothing is thread safe unless explicitly stated. The official docs say it is: https://github.com/liballeg/allegro_wiki/wiki/Frequently-Asked-Questions#is-allegro-thread-safe even though they link to the same forum. – freakish Jan 07 '21 at 08:03
  • I would have left it at that answer as well, if they didn't also back the answer up with a link to a forum post that seems much less confident in the thread safety. – Charlim Jan 07 '21 at 08:07
  • I aggree this is confusing. If I were you I would assume it is not thread safe. – freakish Jan 07 '21 at 08:14

1 Answers1

1

ALLEGRO relies internally on OpenGL (by default) for it's graphics routines, so they are not guaranteed to be thread safe. You can assume the same to be true for audio. All other functions though are indeed thread-safe:

  1. Synchronization routines (mutex,cond...)
  2. Timers
  3. Filesystem and IO

What I do in my programs, is make all graphics calls from a single thread, and all audio calls from a single thread (not necessarily the same). All other threads use ALLEGRO sync routines to synchronize with graphics and audio.

NOTE: Just to clarify, I meant that you shouldn't DRAW from two threads simultaneously. It's alright to create, copy etc. DIFFERENT bitmaps from different threads simultaneously, so long as you don't draw them on the screen.

NOTE 2: I feel like this is obvious, but you shouldn't write to any object in any programming language from two different threads simultaneously.

Promitheas Nikou
  • 511
  • 4
  • 14