---
name: "SDL_SemWait"
section: "3"
platform: "linux"
package: "libsdl1.2-dev"
version: "1.2.15+dfsg2-8"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_SemWait"
---

# SDL\_SemWait(3)

Lock a semaphore and suspend the thread if the semaphore value is zero.

## NAME

SDL\_SemWait - Lock a semaphore and suspend the thread if the semaphore value is zero.

## SYNOPSIS

**#include "SDL.h"** **#include "SDL\_thread.h"**

**int SDL\_SemWait**(**SDL\_sem \*sem**);

## DESCRIPTION

**SDL\_SemWait()** suspends the calling thread until either the semaphore pointed to by **sem** has a positive value, the call is interrupted by a signal or error. If the call is successful it will atomically decrement the semaphore value.

After **SDL\_SemWait()** is successful, the semaphore can be released and its count atomically incremented by a successful call to *SDL\_SemPost*.

## RETURN VALUE

Returns **0** if successful or **-1** if there was an error (leaving the semaphore unchanged).

## EXAMPLES

```
if (SDL_SemWait(my_sem) == -1) {
        return WAIT_FAILED;
}
...
SDL_SemPost(my_sem);
```

## SEE ALSO

**SDL\_CreateSemaphore**, **SDL\_DestroySemaphore**, **SDL\_SemTryWait**, **SDL\_SemWaitTimeout**, **SDL\_SemPost**, **SDL\_SemValue**
