SDL_stdinc - thread safe calls? Missing functions?

Hi. I have two questions.

(1) Are the functions in SDL_stdinc.h thread safe “out of the box”? For example, can two SDL threads call SDL_malloc or SDL_free (on different pointers) concurrently without risk introducing data races to the program?

(2) It seems like SDL_stdinc doesn’t have a SDL_rand neither a SDL_srand. It would be useful to have those for thread safety issues. Isn’t SDL_stdinc supposed to have those functions, or are they really missing?

By the way, I’m on SDL2 here.

2014-12-17 12:16 GMT-03:00, phao :

Hi. I have two questions.

(1) Are the functions in SDL_stdinc.h thread safe “out of the box”? For
example, can two SDL threads call SDL_malloc or SDL_free (on different
pointers) concurrently without risk introducing data races to the program?

Looked into the code, and it normally tries to just use malloc and
free (so same rules apply). The only time it doesn’t is when the
platform has them missing (which is already kind of a problem), in
which case it uses dlmalloc with USE_LOCKS enabled (which enables
thread-safety). Not sure if I missed some other case.

But yeah I guess it’s safe to assume the dynamic memory functions are
supposed to be thread-safe.

Ugh should have paid more attention before replying.

2015-01-04 3:18 GMT-03:00, Sik the hedgehog <@Sik_the_hedgehog>:

But yeah I guess it’s safe to assume the dynamic memory functions are
supposed to be thread-safe.

It is when dlmalloc is used, when it isn’t then it depends on the
version of the C library (but if you’re worrying about that then
chances are that you’re using one that is thread-safe anyway).

Just one addition - USE_LOCKS is only enabled by default in SDL?s dmalloc implementation as of last May, so anything that uses SDL_malloc or SDL_free in an official Windows build of SDL 2.0.3 or older isn?t thread-safe.On Jan 4, 2015, at 2:18 AM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

Looked into the code, and it normally tries to just use malloc and
free (so same rules apply). The only time it doesn’t is when the
platform has them missing (which is already kind of a problem), in
which case it uses dlmalloc with USE_LOCKS enabled (which enables
thread-safety). Not sure if I missed some other case.

But yeah I guess it’s safe to assume the dynamic memory functions are
supposed to be thread-safe.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2015-01-04 3:21 GMT-03:00, Alex Szpakowski :

Just one addition - USE_LOCKS is only enabled by default in SDL?s dmalloc
implementation as of last May, so anything that uses SDL_malloc or SDL_free
in an official Windows build of SDL 2.0.3 or older isn?t thread-safe.

That’s what I get for looking only in the source code for one version

.> (if you build it yourself it isn’t hard to just add the define
anyway)

Thanks. I’ll look into building SDL myself then.

=)

You might want to use current Mercurial trunk to do that. We’re
gettin’ on toward 2.0.4 by now. Although SDL2 is already getting
used in commercial games, the fact is that SDL2 up through 2.0.3 has
had some rather significant bugs devs have been ironing out. The
release of 2.0.4 has been pushed back quite awhile thus far as the
major niggling bugs get squashed. If you’re going to use your own
build for development now, plan on 2.0.4 being out by the time you
get there and the folks 'round here will do all that can be done to
accommodate. :smiley:

That needs to include me. sigh I’ve sadly neglected a few tasks
of late.

JosephOn Sun, Jan 04, 2015 at 01:59:51PM +0000, phao wrote:

Thanks. I’ll look into building SDL myself then.

=)