Cleaning semaphores

If your SDL application crashes, it doesn’t clean up sempahores.

Here’s how you can remove them in one fell swoop in bash:

ipcs -s | fgrep $USER | awk ‘{print $1}’ |
while read id; do ipcrm sem $id; done

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

“Sam” == Sam Lantinga writes:

Sam> If your SDL application crashes, it doesn't clean up
Sam> sempahores.  Here's how you can remove them in one fell swoop
Sam> in bash:

Sam> ipcs -s | fgrep $USER | awk '{print $1}' | while read id; do
Sam> ipcrm sem $id; done

How possible is it to make SDL automatically clean up semaphores from
the past upon startup? I’d guess it would be easy to do and that you
should do it.

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

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

–Cliff
@Clifford_T_Matthews

How possible is it to make SDL automatically clean up semaphores from
the past upon startup? I’d guess it would be easy to do and that you
should do it.

It’s possible, but not a good idea. There’s no way to tell that it was
SDL that created those semaphores. My code fragment assumed that SDL was
the only thing that created semaphores on your system.

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

“Sam” == Sam Lantinga writes:

>> How possible is it to make SDL automatically clean up
>> semaphores from the past upon startup?  I'd guess it would be
>> easy to do and that you should do it.

Sam> It's possible, but not a good idea.  There's no way to tell
Sam> that it was SDL that created those semaphores.  My code
Sam> fragment assumed that SDL was the only thing that created
Sam> semaphores on your system.

How about forking off a child whose job it is to clean them up if the
parent dies unexpectedly?

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

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

How about forking off a child whose job it is to clean them up if the
parent dies unexpectedly?

That seems like a hack. A better solution is to have fewer semaphores and
maybe some default cleanup code installed on the signal handlers.

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