[SDL] Mutexes failing!

Tyler Montbriand tsm at accesscomm.ca
Fri Nov 14 18:18:01 PST 2003


This might explain why I'm having such a hard time getting conditional 
variables to work as I think they should...  this following code executes, 
printing "Locked mutex." 10 times then exiting normally.  wtf?  What could 
cause mutexes to fail so completely on a LINUX system?

#include <SDL/SDL.h>
#include <SDL/SDL_mutex.h>
#include <SDL/SDL_thread.h>

int main(int argc, char *argv[])
{
  int n;
  SDL_mutex *mutex=NULL;

  if(SDL_Init(SDL_INIT_EVERYTHING)<0)
  {
    fprintf(stderr,"Can't init SDL: %s\n",SDL_GetError());
    return(1);
  }

  mutex=SDL_CreateMutex();
  if(mutex==NULL)
  {
    fprintf(stderr,"Couldn't create mutex!\n");
  {
    fprintf(stderr,"Couldn't create mutex!\n");
    return(1);
  }

  for(n=0; n<10; n++)
  {
    if(SDL_mutexP(mutex)<0)
      fprintf(stderr,"Can't lock mutex!? %s\n",SDL_GetError());
    else
      fprintf(stderr,"Locked mutex.\n");
  }

  SDL_DestroyMutex(mutex);

  return(0);
}





More information about the SDL mailing list