Well, global state is global, right, not per thread. And using a mutex
kinds of negates the point of threads (especially as you’d have to
keep it for long periods of time, or randomly insert “give up the
mutex, re-take it, and re-select the context” in your long
operations).
I think in some cases it ends up thread local anyway.
For example, most of the “state like” variables in SDL would end up copied to
a new thread. Once in that new thread, changes there would generally not be
reflected back to the main thread.
If these variables were referred to through pointers instead, then it would
remain global, but they aren’t now.
For example, you could have two separate windows (or a window and a
texture target, or two texture targets, soon enough) that you could
draw to using two threads, and there’s really no reason why I’d hold a
single common mutex for the two separate resources. It’s not obvious
at all to me that you really should use a mutex. If the underlying
platform can’t support this kind of thing, then SDL can hide that, but
by having the global state, it entirely precludes the possibility of
ever doing it, even on platforms that are fully multi-thread safe.
You’d probably end up holding a mutex for the video system in general. This I
do not recommend, but fortunately the texture/renderer/multi-window system is
new in 1.3 so backwards compatibility at least is not an issue. Using a
passed state system there does not break any existing API from 1.2.
That said, I’m playing both sides here, because I’m not very big on
threads, and I think that there’s good value in having an API that
can’t be abused (if the API had all the trappings of being
thread-safe, but the implementation wasn’t really, it would work “most
of the time”, then fail in some difficult to debug ways, but a clearly
thread-unsafe API like this will fail spectacularly and reliably at
the first attempt to use it wrong). I just want people to realize that
this is painting SDL into a corner.
Maybe it’s a fine corner to be in, but when you do these things, you
should think about it first.
Personally, I like threads. If I could I’d have a separate thread for
networking, another for video, a third for sound, fourth for events, and
fifth, sixth, whatever, for everything else. But I know better.
In general, I prefer to assume the programmer is fairly intelligent and knows
what he/she is doing. That said, I prefer API’s that don’t put many
restrictions on how they can be used. I personally believe SDL should support
multithreading, but let the user handle mutexes and such to avoid the
performance penalty in single threaded applications. Where such mutexes might
be necessary should, of course, be thoroughly documented though…
Hmm, I think you meant the reverse, right? ABI <=> API?
ABI => Binary
API => Programming/source
changing position of members in structures breaks ABI, but not API.
changing function declarations breaks both.
There’s no “select mouse” function, like for the rest? Or is that the
fix? Haven’t used that bit yet…
There is actually a SDL_SelectMouse() function in SDL 1.3, but the state it
sets is only ever used by the cursor functions, not by the rest of the mouse
API (though the source documentation says otherwise). It’s listed under bug
758.On Monday, 6 July 2009 20:47:13 Pierre Phaneuf wrote: