Wiki Page Content

Differences between revisions 6 and 7
Revision 6 as of 2011-03-18 21:27:22
Size: 1405
Editor: SheenaSmith
Comment: camelcase pragma change, fixed links
Revision 7 as of 2013-08-08 23:19:53
Size: 913
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 destroy a mutex. Use this function to destroy a mutex created with [[SDL_CreateMutex]]().
Line 17: Line 15:
||'''mutex''' ||^the mutex to destroy^ || ||'''mutex''' ||the mutex to destroy||
Line 21: Line 19:
{{{#!highlight cpp
SDL_mutex *mutex;
<<Include(SDL_CreateMutex, , , from="## Begin Mutex Example", to="## End Mutex Example")>>
Line 24: Line 21:
//First create the mutex..
mutex = SDL_CreateMutex();

// ... use mutex in code


// When done using the mutex, destroy it

// MAKE sure to unlock the mutex prior to destroying it
if( SDL_mutexV( mutex ) )
  printf("\nSDL Mutex unlock error:%s", SDL_GetError());
else
  // When done with the mutex delete it
  SDL_DestroyMutex( mutex );
}}}
Line 40: Line 22:
[[SDL_DestroyMutex]] must be called on any mutex that is no longer needed. Failure to destroy a mutex will result in a system memory or resource leak. While it is safe to destroy a mutex that is UNLOCKED, it is not safe to attempt to destroy a locked mutex and may result in undefined behavior depending on the platform.

Any attempt to reference a mutex after it has been destroyed will cause access to an invalid memory pointer which may lead to memory corruption or a segmentation fault.
This function must be called on any mutex that is no longer needed. Failure to destroy a mutex will result in a system memory or resource leak. While it is safe to destroy a mutex that is UNLOCKED, it is not safe to attempt to destroy a locked mutex and may result in undefined behavior depending on the platform.
Line 45: Line 25:
 . [[SDL_CreateMutex]] *  .[[SDL_CreateMutex]]
.[[SDL_LockMutex]]
 .[[SDL_UnlockMutex]]

SDL_DestroyMutex

Use this function to destroy a mutex created with SDL_CreateMutex().

Syntax

void SDL_DestroyMutex(SDL_mutex* mutex)

Function Parameters

mutex

the mutex to destroy

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

This function must be called on any mutex that is no longer needed. Failure to destroy a mutex will result in a system memory or resource leak. While it is safe to destroy a mutex that is UNLOCKED, it is not safe to attempt to destroy a locked mutex and may result in undefined behavior depending on the platform.


CategoryAPI, CategoryMutex

None: SDL_DestroyMutex (last edited 2013-10-04 13:35:45 by urkle)

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