Semaphores

Um… I got home yesterday, carefully carrying the disk containing
the brand new 0.6j archive. Untarred, compiled, modified my little
test programs to do things the j-way (i.e. SDL_FULLSCREEN, no new
surface from Lock, etc) and ran. Big surprise: nothing happens. My
window opens (I run in Linux/X11), but there’s nothing in it. I can’t
even quit – the game has hung!

I comment out all the sprite-drawing, enemy handling, input sensing,
and player updating code. That leaves my main loop doing two things;
a) clearing the screen, and
b) updating it (SDL_UpdateRect()).

Still nothing, and no quitting. OK. I hack the screen-clearing code,
which is essentially just a lock followed by a for-looped memset()
and an unlock, to show an error if the lock fails. Guess what? It
did, and SDL claims the reason to be its failure to create a
semaphore. Que?

Eventually I had to reboot since the system apparantly ran out of
semaphores. Odd. I tried the examples/warp program, which ran fine.
Mostly, it is somewhat flakey too; sometimes the window opens, you
can just barely see the first frame displayed, then the window closes
and the program terminates, all spontanously. Run it again, and it
might work, or it might die immediately. Very weird.

All in all, I really can’t say that 0.6j was an improvement over the
g revision… :slight_smile:

/Emil

Yeah, this is precisely what happened to me last night. The quit code
just doesn’t work by default…

trash the threads… :slight_smile:

njh

Still nothing, and no quitting. OK. I hack the screen-clearing code,
which is essentially just a lock followed by a for-looped memset()
and an unlock, to show an error if the lock fails. Guess what? It
did, and SDL claims the reason to be its failure to create a
semaphore. Que?

It sounds like your system is using libc 6 and pthreads ?
Is that true?

Eventually I had to reboot since the system apparantly ran out of
semaphores.

I assume you have IPC enabled in the kernel, right?

Odd. I tried the examples/warp program, which ran fine.
Mostly, it is somewhat flakey too; sometimes the window opens, you
can just barely see the first frame displayed, then the window closes
and the program terminates, all spontanously. Run it again, and it
might work, or it might die immediately. Very weird.

That sounds like the X11 multi-threaded problem which would be fixed
by disabling asynchronous input. Just for kicks, put a call to
SDL_ThreadEvents(0); before the call to SDL_Init() in the warp demo
and see if that fixes the problem.

All in all, I really can’t say that 0.6j was an improvement over the
g revision… :slight_smile:

I would have to agree. :slight_smile:
– still workin…

Once we decide to do with the event mechanism, I’ll put out SDL 0.6k
with the event changes.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Yeah, this is precisely what happened to me last night. The quit code
just doesn’t work by default…

Em, I think the problem actually is that I do signal(SIGINT, SIG_IGN) in
the event thread. The effect of that isn’t really defined in the posix
standard, and changes between versions of Linux and pthreads.

trash the threads… :slight_smile:

Here are the benefits/problems:

Plus:
No more quirky problems with X11 and events
Less event handling overhead
Better performance under X11
Guaranteed events when you want them – no relying on OS scheduler
No more funky signal handler interactions

Minus:
No more asynchronous events
No more event callbacks
You need to handle events often to update the mouse cursor motion
The event queue code won’t go away – needed for BeOS and SIGINT

As an aside, it is possible to generate an "event may be pending"
interrupt in the form of a callback that can update global variables,
unfortunately it will be triggered on every graphics update under X11
and every windows message under Win32, so they don’t actually translate
into and event ready.

Code would look something like this:

static int event_pending = 0;

void event_interrupt(void)
{
event_pending = 1;
}

main()
{
SDL_Event event;

GameInit();

while ( ! game_over ) {
	if ( event_pending ) {
		while ( SDL_EventPending(&event) ) {
			ProcessEvent(&event);
		}
		event_pending = 0;
	}
	RunGameFrame();
}

}

I realize this wouldn’t be useful for most of you, but it’s the best
I can offer as far as interrupt notification.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

It sounds like your system is using libc 6 and pthreads ?
Is that true?

No on both accounts, I’m afraid… I added a fprintf() to
SDL_CreateMutex() in the SDL_mutex.c’s SVR4-half, and that sure is
running. So I definitely ain’t using pthreads. I’m also fairly sure
that my system uses libc 5.

Eventually I had to reboot since the system apparantly ran out of
semaphores.

I assume you have IPC enabled in the kernel, right?

Um… I don’t know, actually. I’ll have to look into that.

Odd. I tried the examples/warp program, which ran fine.
Mostly, it is somewhat flakey too; sometimes the window opens, you
can just barely see the first frame displayed, then the window closes
and the program terminates, all spontanously. Run it again, and it
might work, or it might die immediately. Very weird.

That sounds like the X11 multi-threaded problem which would be fixed
by disabling asynchronous input. Just for kicks, put a call to
SDL_ThreadEvents(0); before the call to SDL_Init() in the warp demo
and see if that fixes the problem.

Will do.

/EmilOn Thu, 30 Apr 1998, Sam Lantinga wrote:

I assume you have IPC enabled in the kernel, right?

Right.

Odd. I tried the examples/warp program, which ran fine.
Mostly, it is somewhat flakey too; sometimes the window opens, you
can just barely see the first frame displayed, then the window closes
and the program terminates, all spontanously. Run it again, and it
might work, or it might die immediately. Very weird.

That sounds like the X11 multi-threaded problem which would be fixed
by disabling asynchronous input. Just for kicks, put a call to
SDL_ThreadEvents(0); before the call to SDL_Init() in the warp demo
and see if that fixes the problem.

Nope, no detectable improvement. It’s still flaky as h*ll.

/EmilOn Thu, 30 Apr 1998, Sam Lantinga wrote:

I assume you have IPC enabled in the kernel, right?

Right.

Are you linking with the right library? What is the output of ‘ldd warp’ ?

I’m not at home at the moment, so I can’t answer that question
relaibly. However, I’m “pretty sure” that the correct libraries are
being used (I’ve copied SDL-0.6j/lib/* to /usr/local/lib). The test/
programs work, including the one which reads out the version number.
Also, my own programs all “work” with the new way of handling
fullscreen, locking etc (that is, they compile and run, but generally
fail to lock surfaces).

I tried writing a small test program yesterday, and it seems that one
of the most critical things is SDL_LockSurface(). If I guard the
locks with SDL_MUSTLOCK()s, avoiding locking when it’s not necessary,
I can get a small program to run. That program does no blitting,
though.

Nope, no detectable improvement. It’s still flaky as h*ll.

Damn…

Yup.

/EmilOn Fri, 1 May 1998, Sam Lantinga wrote:

On Thu, 30 Apr 1998, Sam Lantinga wrote:

Yeah, this is precisely what happened to me last night. The quit code
just doesn’t work by default…

What kind of system are you testing this on, NJH?
Try this patch, and let me know if it hels:

diff -u -r1.1 SDL_eventloop.c
— SDL_eventloop.c 1998/04/29 01:28:52 1.1
+++ SDL_eventloop.c 1998/05/02 06:14:53
@@ -437,7 +437,7 @@
switch (i) {
case SIGINT: {
/* Ignore keyboard interrupt (SDL_QUITEVENT) */

  •                           signal(i, SIG_IGN);
    
  •                           //signal(i, SIG_IGN);
                      }
                      break;
    

#if defined(SDL_USE_PTHREADS) && defined(linux)
@@ -495,7 +495,7 @@
switch (i) {
case SIGINT: {
/* Ignore keyboard interrupt (SDL_QUITEVENT) */

  •                           signal(i, SIG_IGN);
    
  •                           //signal(i, SIG_IGN);
                      }
                      break;
    

#if defined(SDL_USE_PTHREADS) && defined(linux)—

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/