The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_stdinc - thread safe calls? Missing functions?
phao


Joined: 24 Nov 2014
Posts: 7
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?
phao


Joined: 24 Nov 2014
Posts: 7
By the way, I'm on SDL2 here.
SDL_stdinc - thread safe calls? Missing functions?
Sik


Joined: 26 Nov 2011
Posts: 905
2014-12-17 12:16 GMT-03:00, phao:
Quote:
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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_stdinc - thread safe calls? Missing functions?
Sik


Joined: 26 Nov 2011
Posts: 905
Ugh should have paid more attention before replying.

2015-01-04 3:18 GMT-03:00, Sik the hedgehog:
Quote:
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).
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_stdinc - thread safe calls? Missing functions?
Alex Szpakowski
Guest

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 wrote:

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_stdinc - thread safe calls? Missing functions?
Sik


Joined: 26 Nov 2011
Posts: 905
2015-01-04 3:21 GMT-03:00, Alex Szpakowski:
Quote:
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
Quote:
.> (if you build it yourself it isn't hard to just add the define
anyway)
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
phao


Joined: 24 Nov 2014
Posts: 7
Thanks. I'll look into building SDL myself then.

=)
SDL_stdinc - thread safe calls? Missing functions?
Joseph Carter


Joined: 20 Sep 2013
Posts: 279
On Sun, Jan 04, 2015 at 01:59:51PM +0000, phao wrote:
Quote:
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. Very Happy

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

Joseph

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org