简体   繁体   中英

How can I determine which Allegro library functions are threadsafe?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM