---
name: "SDL_DetachThread"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_DetachThread"
---

# SDL\_DetachThread(3)

Let a thread clean up on exit without intervention.

## NAME

SDL\_DetachThread - Let a thread clean up on exit without intervention.

## HEADER FILE

Defined in SDL3/SDL\_thread.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**void SDL\_DetachThread(SDL\_Thread \*thread);**

## DESCRIPTION

A thread may be "detached" to signify that it should not remain until another thread has called  **SDL\_WaitThread** () on it. Detaching a thread is useful for long-running threads that nothing needs to synchronize with or further manage. When a detached thread is done, it simply goes away.

There is no way to recover the return code of a detached thread. If you need this, don't detach the thread and instead use

**SDL\_WaitThread** ().

Once a thread is detached, you should usually assume the

**SDL\_Thread**\
  isn't safe to reference again, as it will become invalid immediately upon the detached thread's exit, instead of remaining until someone has called  **SDL\_WaitThread** () to finally clean it up. As such, don't detach the same thread more than once.

If a thread has already exited when passed to

**SDL\_DetachThread** (), it will stop waiting for a call to

**SDL\_WaitThread** () and clean up immediately. It is not safe to detach a thread that might be used with

**SDL\_WaitThread** ().

You may not call  **SDL\_WaitThread** () on a thread that has been detached. Use either that function or this one, but not both, or behavior is undefined.

It is safe to pass NULL to this function; it is a no-op.

## FUNCTION PARAMETERS

- *thread*

  the  **SDL\_Thread**\
    pointer that was returned from the  **SDL\_CreateThread** () call that started this thread.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_CreateThread**(3)](/SDL_CreateThread/3.md), **•**(3), [**SDL\_WaitThread**(3)](/SDL_WaitThread/3.md)
