Wiki Page Content

Differences between revisions 8 and 9
Revision 8 as of 2011-03-18 21:33:08
Size: 1230
Editor: SheenaSmith
Comment: camelcase pragma change, fix category link, RV to standard format
Revision 9 as of 2013-08-08 23:16:34
Size: 953
Editor: Sam Lantinga
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablewidth="100%"style="color: rgb(255, 0, 0); text-align: center;">DRAFT ||
Line 7: Line 5:
Use this function to create a new mutex. ,,The mutex is returned as an initialized and unlocked mutex.,, Use this function to create a new mutex.
Line 19: Line 17:
,,This is a pointer to SDL's internal mutex data structure.,, == Code Examples ==
## Begin Mutex Example
{{{#!highlight cpp
SDL_mutex *mutex;
Line 21: Line 22:
== Code Examples ==
{{{#!highlight cpp
SDL_mutex *mut;

mut=SDL_CreateMutex();
.
.
if(SDL_mutexP(mut)==-1){
  fprintf(stderr, "Couldn't lock mutex\n");
  exit(-1);
}
.
/* Do stuff while mutex is locked */
.
.
if(SDL_mutexV(mut)==-1){
  fprintf(stderr, "Couldn't unlock mutex\n");
  exit(-1);
mutex = SDL_CreateMutex();
if (!mutex) {
  fprintf(stderr, "Couldn't create mutex\n");
  return;
Line 41: Line 28:
SDL_DestroyMutex(mut); if (SDL_LockMutex(mutex) == 0) {
  /* Do stuff while mutex is locked */
  SDL_UnlockMutex(mutex);
} else {
  fprintf(stderr, "Couldn't lock mutex\n");
}

SDL_DestroyMutex(mutex);
Line 43: Line 37:
*<<BR>><<Color2(green,Should this example be Included on the SDL_!DestroyMutex page? What about SDL_mutexP or SDL_mutexV?)>> ## End Mutex Example
Line 49: Line 43:
 . [[SDL_DestroyMutex]] *
 . [[SDL_mutexP]] *
 . [[SDL_mutexV]] *
 .[[SDL_DestroyMutex]]
 .[[SDL_LockMutex]]
 .[[SDL_UnlockMutex]]

SDL_CreateMutex

Use this function to create a new mutex.

Syntax

SDL_mutex* SDL_CreateMutex(void)

Return Value

Returns the initialized and unlocked mutex or NULL on failure; call SDL_GetError() for more information.

Code Examples

SDL_mutex *mutex;

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

if (SDL_LockMutex(mutex) == 0) {
  /* Do stuff while mutex is locked */
  SDL_UnlockMutex(mutex);
} else {
  fprintf(stderr, "Couldn't lock mutex\n");
}

SDL_DestroyMutex(mutex);

Remarks

You can add useful comments here


CategoryAPI, CategoryMutex

None: SDL_CreateMutex (last edited 2015-08-21 21:22:59 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit