Wiki Page Content

Differences between revisions 3 and 4
Revision 3 as of 2010-06-02 00:25:07
Size: 1070
Editor: SheenaSmith
Comment: add introduction content
Revision 4 as of 2010-06-08 20:16:18
Size: 2490
Editor: SheenaSmith
Comment: add introductory information
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
||<tablewidth="100%" style="color: #FF0000;" :> DRAFT||
Line 16: Line 17:
^Mutex functions are used to coordinate multiple threads using or calling the same resource to avoid interference that may cause instability in the program. Threads take turns locking (accessing) the resource one at a time. Waiting threads are queued up based on the mutex algorithm and take their turn locking (accessing) the shared resource as each previous function unlocks (releases) the resource.^ Functions in this group provide thread synchronization primitives for functions in the [[CategoryThread|Thread Management]] group.
Line 18: Line 19:
^Semaphore functions are used to determine whether resources are available to be allocated to a process in the queue.^ === Mutex ===
^If you have heard the phrase "mutually exclusive" then you already know the basic idea of a mutex. Mutex (__mut__ual __ex__clusion) functions are used to protect data structures. By coordinating multiple threads using or calling the same data source a mutex prevents interference between threads that may cause instability in the program. Threads take turns locking the mutex (accessing the resource) one at a time. Waiting threads are queued up based on the mutex algorithm and take their turn locking (accessing) the shared resource as each previous thread unlocks (releases) the mutex. Only the thread that has locked the mutex can access the data structure to read or write to it.^
 ^''Analogy:'' This is a little like needing a key to access the restroom at a gas station.^
  *^The mutex is the clerk at the counter who controls access to the key.^
  *^The restroom is the data structure.^
  *^An individual needing to use the restroom is a thread.^
 ^The person who currently possesses the key has access to use the restroom and everyone else must wait. Once the key is returned to the clerk anyone waiting for the restroom may then attempt to get the key from the clerk. Eventually each waiting person will get their turn, but the restroom cannot be used by more than one person at a time in this way. (Please disregard the 'human factor' in this analogy, which allows individuals to break rules. Thankfully computers are much less prone to do so.)^ ;)
Line 20: Line 27:
Functions in this group provide thread synchronization primitives for functions in the [[CategoryThreads]] group. === Semaphore ===
^Semaphore functions are used to determine whether a data structure is available to be allocated to a thread. Semaphores count - up or down. In both cases the critical value is 0. For a semaphore counting up, 0 indicates that there is nothing available to be used/worked on. For a semaphore counting down, 0 indicates that^

=== Condition Variable ===

DRAFT

Thread Synchronization Primitives

Primary Include: SDL_mutex.h

Other Includes: SDL_thread.h, SDL_stdinc.h, SDL_error.h

Introduction

Functions in this group provide thread synchronization primitives for functions in the Thread Management group.

Mutex

If you have heard the phrase "mutually exclusive" then you already know the basic idea of a mutex. Mutex (__mut__ual __ex__clusion) functions are used to protect data structures. By coordinating multiple threads using or calling the same data source a mutex prevents interference between threads that may cause instability in the program. Threads take turns locking the mutex (accessing the resource) one at a time. Waiting threads are queued up based on the mutex algorithm and take their turn locking (accessing) the shared resource as each previous thread unlocks (releases) the mutex. Only the thread that has locked the mutex can access the data structure to read or write to it.

  • ''Analogy:'' This is a little like needing a key to access the restroom at a gas station.

    • The mutex is the clerk at the counter who controls access to the key.

    • The restroom is the data structure.

    • An individual needing to use the restroom is a thread.

    The person who currently possesses the key has access to use the restroom and everyone else must wait. Once the key is returned to the clerk anyone waiting for the restroom may then attempt to get the key from the clerk. Eventually each waiting person will get their turn, but the restroom cannot be used by more than one person at a time in this way. (Please disregard the 'human factor' in this analogy, which allows individuals to break rules. Thankfully computers are much less prone to do so.) ;)

Semaphore

Semaphore functions are used to determine whether a data structure is available to be allocated to a thread. Semaphores count - up or down. In both cases the critical value is 0. For a semaphore counting up, 0 indicates that there is nothing available to be used/worked on. For a semaphore counting down, 0 indicates that

Condition Variable

Functions


CategoryCategory

None: CategoryMutex (last edited 2016-03-27 21:45:54 by PhilippWiesemann)

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