>SDL_CreateSemaphore<
/TITLE
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
REL="HOME"
TITLE="SDL Library Documentation"
REL="UP"
TITLE="Multi-threaded Programming"
REL="PREVIOUS"
TITLE="SDL_mutexV"
HREF="sdlmutexv.html"><
LINK
REL="NEXT"
TITLE="SDL_DestroySemaphore"
HREF="sdldestroysemaphore.html"><
/HEAD
CLASS="REFENTRY"
BGCOLOR="#FFF8DC"
TEXT="#000000"
LINK="#0000ee"
VLINK="#551a8b"
ALINK="#ff0000"
CLASS="NAVHEADER"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
COLSPAN="3"
ALIGN="center"
>SDL Library Documentation<
/TH
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
HREF="sdlmutexv.html"
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
HREF="sdldestroysemaphore.html"
ALIGN="LEFT"
NAME="SDLCREATESEMAPHORE"
CLASS="REFNAMEDIV"
NAME="AEN7387"
>SDL_CreateSemaphore -- Creates a new semaphore and assigns an initial
value to it.<
/DIV
CLASS="REFSYNOPSISDIV"
NAME="AEN7390"
CLASS="FUNCSYNOPSIS"
NAME="AEN7391"
CLASS="FUNCSYNOPSISINFO"
>#include "SDL.h"
#include
"SDL_thread.h"<
/PRE
CLASS="FUNCDEF"
CLASS="FSFUNC"
>
(Uint32 initial_value
);<
/CODE
CLASS="REFSECT1"
NAME="AEN7397"
CLASS="FUNCTION"
>SDL_CreateSemaphore
()<
/TT
> creates a new semaphore and
initializes it with the
value <
TT
CLASS="PARAMETER"
>.
Each locking operation on the semaphore by
HREF="sdlsemwait.html"
>,
HREF="sdlsemtrywait.html"
> or
HREF="sdlsemwaittimeout.html"
>
will atomically decrement the semaphore value. The locking operation will be blocked
if the semaphore value is not positive (greater than zero). Each unlock operation by
HREF="sdlsempost.html"
>
will atomically increment the semaphore
value.<
/P
CLASS="REFSECT1"
NAME="AEN7406"
>Returns a pointer to an initialized semaphore or
CLASS="RETURNVALUE"
> if there was an error.<
/P
CLASS="REFSECT1"
NAME="AEN7410"
CLASS="PROGRAMLISTING"
>SDL_sem *my_sem;
my_sem = SDL_CreateSemaphore(INITIAL_SEM_VALUE);
if (my_sem == NULL) {
return CREATE_SEM_FAILED;
CLASS="REFSECT1"
NAME="AEN7414"
HREF="sdldestroysemaphore.html"
CLASS="FUNCTION"
>SDL_DestroySemaphore<
/TT
>,
HREF="sdlsemwait.html"
CLASS="FUNCTION"
>,
HREF="sdlsemtrywait.html"
CLASS="FUNCTION"
>,
HREF="sdlsemwaittimeout.html"
CLASS="FUNCTION"
>,
HREF="sdlsempost.html"
CLASS="FUNCTION"
>,
HREF="sdlsemvalue.html"
CLASS="FUNCTION"
CLASS="NAVFOOTER"
ALIGN="LEFT"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
WIDTH="33%"
ALIGN="left"
VALIGN="top"
HREF="sdlmutexv.html"
WIDTH="34%"
ALIGN="center"
VALIGN="top"
HREF="index.html"
WIDTH="33%"
ALIGN="right"
VALIGN="top"
HREF="sdldestroysemaphore.html"
WIDTH="33%"
ALIGN="left"
VALIGN="top"
WIDTH="34%"
ALIGN="center"
VALIGN="top"
HREF="thread.html"
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>SDL_DestroySemaphore<
/TD
>