| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Thread
Contents
Description
SDL offers cross-platform thread management functions. These are mostly concerned with starting threads, setting their priority, and dealing with their termination.
In addition, there is support for Thread Local Storage (data that is unique to each thread, but accessed from a single key).
On platforms without thread support (such as Emscripten when built without pthreads), these functions still exist, but things like will report failure without doing anything.createThread
If you're going to work with threads, you almost certainly need to have a good understanding of thread safety measures: locking and synchronization mechanisms are handled by the functions in SDL_mutex.h. The SDL thread object.
These are opaque data.
- See also
,createThreadwaitThread
FFI conventions
Unsuffixed aliases are unsafe foreign imports; aliases suffixed Safe are safe. Functions whose callbacks fire during the call export only the Safe alias (the genuine unsafe import stays reachable under SDL3.Sys.Bindgen.Thread.Unsafe); functions curated unsafe-only export only the unsuffixed one. Each alias's documentation records its flavor and rationale.
The C shims are functions this package defines in C over what the FFI cannot call directly (variadic functions, function-like macros), each named after what it wraps; the same flavor rules apply. Their raw imports live under SDL3.Sys.Bindgen.ThreadShims.
Full conventions: SDL3.Sys.
Since: 3.2.0
Synopsis
- module SDL3.Sys.Bindgen.Thread
- createThreadRuntime :: SDL_ThreadFunction -> PtrConst CChar -> Ptr Void -> SDL_FunctionPointer -> SDL_FunctionPointer -> IO (Ptr SDL_Thread)
- createThreadRuntimeSafe :: SDL_ThreadFunction -> PtrConst CChar -> Ptr Void -> SDL_FunctionPointer -> SDL_FunctionPointer -> IO (Ptr SDL_Thread)
- createThreadWithPropertiesRuntime :: SDL_PropertiesID -> SDL_FunctionPointer -> SDL_FunctionPointer -> IO (Ptr SDL_Thread)
- createThreadWithPropertiesRuntimeSafe :: SDL_PropertiesID -> SDL_FunctionPointer -> SDL_FunctionPointer -> IO (Ptr SDL_Thread)
- getThreadName :: Ptr SDL_Thread -> IO (PtrConst CChar)
- getThreadNameSafe :: Ptr SDL_Thread -> IO (PtrConst CChar)
- getCurrentThreadID :: IO SDL_ThreadID
- getCurrentThreadIDSafe :: IO SDL_ThreadID
- getThreadID :: Ptr SDL_Thread -> IO SDL_ThreadID
- getThreadIDSafe :: Ptr SDL_Thread -> IO SDL_ThreadID
- setCurrentThreadPriority :: SDL_ThreadPriority -> IO Bool
- setCurrentThreadPrioritySafe :: SDL_ThreadPriority -> IO Bool
- waitThread :: Ptr SDL_Thread -> Ptr CInt -> IO ()
- waitThreadSafe :: Ptr SDL_Thread -> Ptr CInt -> IO ()
- getThreadState :: Ptr SDL_Thread -> IO SDL_ThreadState
- getThreadStateSafe :: Ptr SDL_Thread -> IO SDL_ThreadState
- detachThread :: Ptr SDL_Thread -> IO ()
- detachThreadSafe :: Ptr SDL_Thread -> IO ()
- getTLS :: Ptr SDL_TLSID -> IO (Ptr Void)
- getTLSSafe :: Ptr SDL_TLSID -> IO (Ptr Void)
- setTLS :: Ptr SDL_TLSID -> PtrConst Void -> SDL_TLSDestructorCallback -> IO Bool
- setTLSSafe :: Ptr SDL_TLSID -> PtrConst Void -> SDL_TLSDestructorCallback -> IO Bool
- cleanupTLS :: IO ()
- cleanupTLSSafe :: IO ()
- createThread :: SDL_ThreadFunction -> PtrConst CChar -> Ptr Void -> IO (Ptr SDL_Thread)
- createThreadSafe :: SDL_ThreadFunction -> PtrConst CChar -> Ptr Void -> IO (Ptr SDL_Thread)
- createThreadWithProperties :: SDL_PropertiesID -> IO (Ptr SDL_Thread)
- createThreadWithPropertiesSafe :: SDL_PropertiesID -> IO (Ptr SDL_Thread)
Documentation
module SDL3.Sys.Bindgen.Thread
Function aliases
Arguments
| :: SDL_ThreadFunction |
|
| -> PtrConst CChar |
|
| -> Ptr Void |
|
| -> SDL_FunctionPointer |
|
| -> SDL_FunctionPointer |
|
| -> IO (Ptr SDL_Thread) |
The actual entry point for createThread.
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_CreateThreadRuntime. The safe flavor iscreateThreadRuntimeSafe: the entry function runs on the spawned thread, not during the call. - C declaration
SDL_CreateThreadRuntime, defined atSDL3/SDL_thread.h 340:42
Since: 3.2.0
createThreadRuntimeSafe Source #
Arguments
| :: SDL_ThreadFunction |
|
| -> PtrConst CChar |
|
| -> Ptr Void |
|
| -> SDL_FunctionPointer |
|
| -> SDL_FunctionPointer |
|
| -> IO (Ptr SDL_Thread) |
The actual entry point for createThread.
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_CreateThreadRuntime. The unsafe flavor iscreateThreadRuntime: the entry function runs on the spawned thread, not during the call. - C declaration
SDL_CreateThreadRuntime, defined atSDL3/SDL_thread.h 340:42
Since: 3.2.0
createThreadWithPropertiesRuntime Source #
Arguments
| :: SDL_PropertiesID |
|
| -> SDL_FunctionPointer |
|
| -> SDL_FunctionPointer |
|
| -> IO (Ptr SDL_Thread) |
The actual entry point for createThreadWithProperties.
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_CreateThreadWithPropertiesRuntime. The safe flavor iscreateThreadWithPropertiesRuntimeSafe: the entry function runs on the spawned thread, not during the call. - C declaration
SDL_CreateThreadWithPropertiesRuntime, defined atSDL3/SDL_thread.h 356:42
Since: 3.2.0
createThreadWithPropertiesRuntimeSafe Source #
Arguments
| :: SDL_PropertiesID |
|
| -> SDL_FunctionPointer |
|
| -> SDL_FunctionPointer |
|
| -> IO (Ptr SDL_Thread) |
The actual entry point for createThreadWithProperties.
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_CreateThreadWithPropertiesRuntime. The unsafe flavor iscreateThreadWithPropertiesRuntime: the entry function runs on the spawned thread, not during the call. - C declaration
SDL_CreateThreadWithPropertiesRuntime, defined atSDL3/SDL_thread.h 356:42
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO (PtrConst CChar) |
Get the thread name as it was specified in .createThread
- Returns
- a pointer to a UTF-8 string that names the specified thread, or NULL if it doesn't have a name.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetThreadName. The safe flavor isgetThreadNameSafe. - C declaration
SDL_GetThreadName, defined atSDL3/SDL_thread.h 378:42
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO (PtrConst CChar) |
Get the thread name as it was specified in .createThread
- Returns
- a pointer to a UTF-8 string that names the specified thread, or NULL if it doesn't have a name.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetThreadName. The unsafe flavor isgetThreadName. - C declaration
SDL_GetThreadName, defined atSDL3/SDL_thread.h 378:42
Since: 3.2.0
getCurrentThreadID :: IO SDL_ThreadID Source #
Get the thread identifier for the current thread.
This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.
This function also returns a valid thread ID when called from the main thread.
- Returns
- the ID of the current thread.
- Thread safety
- It is safe to call this function from any thread.
- See also
getThreadID
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetCurrentThreadID. The safe flavor isgetCurrentThreadIDSafe. - C declaration
SDL_GetCurrentThreadID, defined atSDL3/SDL_thread.h 398:42
Since: 3.2.0
getCurrentThreadIDSafe :: IO SDL_ThreadID Source #
Get the thread identifier for the current thread.
This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.
This function also returns a valid thread ID when called from the main thread.
- Returns
- the ID of the current thread.
- Thread safety
- It is safe to call this function from any thread.
- See also
getThreadID
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetCurrentThreadID. The unsafe flavor isgetCurrentThreadID. - C declaration
SDL_GetCurrentThreadID, defined atSDL3/SDL_thread.h 398:42
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO SDL_ThreadID |
Get the thread identifier for the specified thread.
This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.
- Returns
- the ID of the specified thread, or the ID of the current thread if
threadis NULL. - Thread safety
- It is safe to call this function from any thread.
- See also
getCurrentThreadID
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetThreadID. The safe flavor isgetThreadIDSafe. - C declaration
SDL_GetThreadID, defined atSDL3/SDL_thread.h 417:42
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO SDL_ThreadID |
Get the thread identifier for the specified thread.
This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.
- Returns
- the ID of the specified thread, or the ID of the current thread if
threadis NULL. - Thread safety
- It is safe to call this function from any thread.
- See also
getCurrentThreadID
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetThreadID. The unsafe flavor isgetThreadID. - C declaration
SDL_GetThreadID, defined atSDL3/SDL_thread.h 417:42
Since: 3.2.0
setCurrentThreadPriority Source #
Arguments
| :: SDL_ThreadPriority |
|
| -> IO Bool |
Set the priority for the current thread.
Note that some platforms will not let you alter the priority (or at least, promote the thread to a higher priority) at all, and some require you to be an administrator account. Be prepared for this to fail.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetCurrentThreadPriority. The safe flavor issetCurrentThreadPrioritySafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetCurrentThreadPriority, defined atSDL3/SDL_thread.h 434:34
Since: 3.2.0
setCurrentThreadPrioritySafe Source #
Arguments
| :: SDL_ThreadPriority |
|
| -> IO Bool |
Set the priority for the current thread.
Note that some platforms will not let you alter the priority (or at least, promote the thread to a higher priority) at all, and some require you to be an administrator account. Be prepared for this to fail.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetCurrentThreadPriority. The unsafe flavor issetCurrentThreadPriority. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetCurrentThreadPriority, defined atSDL3/SDL_thread.h 434:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> Ptr CInt |
|
| -> IO () |
Wait for a thread to finish.
Threads that haven't been detached will remain until this function cleans them up. Not doing so is a resource leak.
Once a thread has been cleaned up through this function, the SDL_Thread that references it becomes invalid and should not be referenced again. As such, only one thread may call on another.waitThread
The return code from the thread function is placed in the area pointed to by status, if status is not NULL.
You may not wait on a thread that has been used in a call to . Use either that function or this one, but not both, or behavior is undefined.detachThread
It is safe to pass a NULL thread to this function; it is a no-op.
Note that the thread pointer is freed by this function and is not valid afterward.
- Thread safety
- It is safe to call this function from any thread, but only a single thread can wait any specific thread to finish.
- See also
,createThreaddetachThread
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_WaitThread. The safe flavor iswaitThreadSafe: blocks until the thread exits. - C declaration
SDL_WaitThread, defined atSDL3/SDL_thread.h 472:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> Ptr CInt |
|
| -> IO () |
Wait for a thread to finish.
Threads that haven't been detached will remain until this function cleans them up. Not doing so is a resource leak.
Once a thread has been cleaned up through this function, the SDL_Thread that references it becomes invalid and should not be referenced again. As such, only one thread may call on another.waitThread
The return code from the thread function is placed in the area pointed to by status, if status is not NULL.
You may not wait on a thread that has been used in a call to . Use either that function or this one, but not both, or behavior is undefined.detachThread
It is safe to pass a NULL thread to this function; it is a no-op.
Note that the thread pointer is freed by this function and is not valid afterward.
- Thread safety
- It is safe to call this function from any thread, but only a single thread can wait any specific thread to finish.
- See also
,createThreaddetachThread
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_WaitThread. The unsafe flavor iswaitThread: blocks until the thread exits. - C declaration
SDL_WaitThread, defined atSDL3/SDL_thread.h 472:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO SDL_ThreadState |
Get the current state of a thread.
- Returns
- the current state of a thread, or SDL_THREAD_UNKNOWN if the thread isn't valid.
- Thread safety
- It is safe to call this function from any thread.
- See also
SDL_ThreadState
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetThreadState. The safe flavor isgetThreadStateSafe. - C declaration
SDL_GetThreadState, defined atSDL3/SDL_thread.h 487:45
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO SDL_ThreadState |
Get the current state of a thread.
- Returns
- the current state of a thread, or SDL_THREAD_UNKNOWN if the thread isn't valid.
- Thread safety
- It is safe to call this function from any thread.
- See also
SDL_ThreadState
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetThreadState. The unsafe flavor isgetThreadState. - C declaration
SDL_GetThreadState, defined atSDL3/SDL_thread.h 487:45
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO () |
Let a thread clean up on exit without intervention.
A thread may be "detached" to signify that it should not remain until another thread has called 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.waitThread
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 .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 to finally clean it up. As such, don't detach the same thread more than once.waitThread
If a thread has already exited when passed to , it will stop waiting for a call to detachThread and clean up immediately. It is not safe to detach a thread that might be used with waitThread.waitThread
You may not call on a thread that has been detached. Use either that function or this one, but not both, or behavior is undefined.waitThread
It is safe to pass NULL to this function; it is a no-op.
- Thread safety
- It is safe to call this function from any thread.
- See also
,createThreadwaitThread
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_DetachThread. The safe flavor isdetachThreadSafe. - C declaration
SDL_DetachThread, defined atSDL3/SDL_thread.h 525:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Thread |
|
| -> IO () |
Let a thread clean up on exit without intervention.
A thread may be "detached" to signify that it should not remain until another thread has called 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.waitThread
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 .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 to finally clean it up. As such, don't detach the same thread more than once.waitThread
If a thread has already exited when passed to , it will stop waiting for a call to detachThread and clean up immediately. It is not safe to detach a thread that might be used with waitThread.waitThread
You may not call on a thread that has been detached. Use either that function or this one, but not both, or behavior is undefined.waitThread
It is safe to pass NULL to this function; it is a no-op.
- Thread safety
- It is safe to call this function from any thread.
- See also
,createThreadwaitThread
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_DetachThread. The unsafe flavor isdetachThread. - C declaration
SDL_DetachThread, defined atSDL3/SDL_thread.h 525:34
Since: 3.2.0
Arguments
| :: Ptr SDL_TLSID |
|
| -> IO (Ptr Void) |
Get the current thread's value associated with a thread local storage ID.
- Returns
- the value associated with the ID for the current thread or NULL if no value has been set; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
setTLS
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetTLS. The safe flavor isgetTLSSafe. - C declaration
SDL_GetTLS, defined atSDL3/SDL_thread.h 540:36
Since: 3.2.0
Arguments
| :: Ptr SDL_TLSID |
|
| -> IO (Ptr Void) |
Get the current thread's value associated with a thread local storage ID.
- Returns
- the value associated with the ID for the current thread or NULL if no value has been set; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
setTLS
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetTLS. The unsafe flavor isgetTLS. - C declaration
SDL_GetTLS, defined atSDL3/SDL_thread.h 540:36
Since: 3.2.0
Arguments
| :: Ptr SDL_TLSID |
|
| -> PtrConst Void |
|
| -> SDL_TLSDestructorCallback |
|
| -> IO Bool |
Set the current thread's value associated with a thread local storage ID.
If the thread local storage ID is not initialized (the value is 0), a new ID will be created in a thread-safe way, so all calls using a pointer to the same ID will refer to the same local storage.
Note that replacing a value from a previous call to this function on the same thread does not call the previous value's destructor!
destructor can be NULL; it is assumed that value does not need to be cleaned up if so.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
getTLS
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetTLS. The safe flavor issetTLSSafe: registration; the destructor runs at thread cleanup. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetTLS, defined atSDL3/SDL_thread.h 581:34
Since: 3.2.0
Arguments
| :: Ptr SDL_TLSID |
|
| -> PtrConst Void |
|
| -> SDL_TLSDestructorCallback |
|
| -> IO Bool |
Set the current thread's value associated with a thread local storage ID.
If the thread local storage ID is not initialized (the value is 0), a new ID will be created in a thread-safe way, so all calls using a pointer to the same ID will refer to the same local storage.
Note that replacing a value from a previous call to this function on the same thread does not call the previous value's destructor!
destructor can be NULL; it is assumed that value does not need to be cleaned up if so.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
getTLS
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetTLS. The unsafe flavor issetTLS: registration; the destructor runs at thread cleanup. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetTLS, defined atSDL3/SDL_thread.h 581:34
Since: 3.2.0
cleanupTLS :: IO () Source #
Cleanup all TLS data for this thread.
If you are creating your threads outside of SDL and then calling SDL functions, you should call this function before your thread exits, to properly clean up SDL memory.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_CleanupTLS. The safe flavor iscleanupTLSSafe. - C declaration
SDL_CleanupTLS, defined atSDL3/SDL_thread.h 594:34
Since: 3.2.0
cleanupTLSSafe :: IO () Source #
Cleanup all TLS data for this thread.
If you are creating your threads outside of SDL and then calling SDL functions, you should call this function before your thread exits, to properly clean up SDL memory.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_CleanupTLS. The unsafe flavor iscleanupTLS. - C declaration
SDL_CleanupTLS, defined atSDL3/SDL_thread.h 594:34
Since: 3.2.0
C shims
Arguments
| :: SDL_ThreadFunction |
|
| -> PtrConst CChar |
|
| -> Ptr Void |
|
| -> IO (Ptr SDL_Thread) |
Create a new thread with a default stack size.
The SDL_CreateThread macro as a function. Like the macro, it calls createThreadRuntime with the C runtime's thread entry and exit functions for the platform it is compiled on (_beginthreadex and _endthreadex on Windows, NULL elsewhere), so prefer it to calling createThreadRuntime directly.
This is equivalent to calling createThreadWithProperties with the following properties set:
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER:fnSDL_PROP_THREAD_CREATE_NAME_STRING:nameSDL_PROP_THREAD_CREATE_USERDATA_POINTER:data
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
createThreadWithProperties,waitThread
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
lithon_SDL_CreateThread. The safe flavor iscreateThreadSafe: the entry function runs on the spawned thread, not during the call. - C declaration
lithon_SDL_CreateThread, defined atsdl3-bindgen-sys/SDL_thread_shims.h 54:31
Since: 3.2.0
Arguments
| :: SDL_ThreadFunction |
|
| -> PtrConst CChar |
|
| -> Ptr Void |
|
| -> IO (Ptr SDL_Thread) |
Create a new thread with a default stack size.
The SDL_CreateThread macro as a function. Like the macro, it calls createThreadRuntime with the C runtime's thread entry and exit functions for the platform it is compiled on (_beginthreadex and _endthreadex on Windows, NULL elsewhere), so prefer it to calling createThreadRuntime directly.
This is equivalent to calling createThreadWithProperties with the following properties set:
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER:fnSDL_PROP_THREAD_CREATE_NAME_STRING:nameSDL_PROP_THREAD_CREATE_USERDATA_POINTER:data
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
createThreadWithProperties,waitThread
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
lithon_SDL_CreateThread. The unsafe flavor iscreateThread: the entry function runs on the spawned thread, not during the call. - C declaration
lithon_SDL_CreateThread, defined atsdl3-bindgen-sys/SDL_thread_shims.h 54:31
Since: 3.2.0
createThreadWithProperties Source #
Arguments
| :: SDL_PropertiesID |
|
| -> IO (Ptr SDL_Thread) |
Create a new thread with the specified properties.
The SDL_CreateThreadWithProperties macro as a function, passing the C runtime's thread entry and exit functions like createThread does.
These are the supported properties:
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER: an SDL_ThreadFunction value that will be called at the start of the new thread's life. Required.SDL_PROP_THREAD_CREATE_NAME_STRING: the name of the new thread, which might be available to debuggers. Optional, defaults to NULL.SDL_PROP_THREAD_CREATE_USERDATA_POINTER: an arbitrary app-defined pointer, which is passed to the entry function on the new thread, as its only parameter. Optional, defaults to NULL.SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER: the size, in bytes, of the new thread's stack. Optional, defaults to 0 (system-defined default).
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
createThread,waitThread
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
lithon_SDL_CreateThreadWithProperties. The safe flavor iscreateThreadWithPropertiesSafe: the entry function runs on the spawned thread, not during the call. - C declaration
lithon_SDL_CreateThreadWithProperties, defined atsdl3-bindgen-sys/SDL_thread_shims.h 90:31
Since: 3.2.0
createThreadWithPropertiesSafe Source #
Arguments
| :: SDL_PropertiesID |
|
| -> IO (Ptr SDL_Thread) |
Create a new thread with the specified properties.
The SDL_CreateThreadWithProperties macro as a function, passing the C runtime's thread entry and exit functions like createThread does.
These are the supported properties:
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER: an SDL_ThreadFunction value that will be called at the start of the new thread's life. Required.SDL_PROP_THREAD_CREATE_NAME_STRING: the name of the new thread, which might be available to debuggers. Optional, defaults to NULL.SDL_PROP_THREAD_CREATE_USERDATA_POINTER: an arbitrary app-defined pointer, which is passed to the entry function on the new thread, as its only parameter. Optional, defaults to NULL.SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER: the size, in bytes, of the new thread's stack. Optional, defaults to 0 (system-defined default).
- Returns
- an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
createThread,waitThread
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
lithon_SDL_CreateThreadWithProperties. The unsafe flavor iscreateThreadWithProperties: the entry function runs on the spawned thread, not during the call. - C declaration
lithon_SDL_CreateThreadWithProperties, defined atsdl3-bindgen-sys/SDL_thread_shims.h 90:31
Since: 3.2.0