sdlCreateThread function
- Pointer<
NativeFunction< fn,SdlThreadFunction> > - String? name,
- Pointer<
NativeType> data
Create a new thread with a default stack size.
This is a convenience function, equivalent to calling SDL_CreateThreadWithProperties with the following properties set:
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER
:fn
SDL_PROP_THREAD_CREATE_NAME_STRING
:name
SDL_PROP_THREAD_CREATE_USERDATA_POINTER
:data
Note that this "function" is actually a macro that calls an internal function with two extra parameters not listed here; they are hidden through preprocessor macros and are needed to support various C runtimes at the point of the function call. Language bindings that aren't using the C headers will need to deal with this.
Usually, apps should just call this function the same way on every platform and let the macros hide the details.
\param fn the SDL_ThreadFunction function to call in the new thread.
\param name the name of the thread.
\param data a pointer that is passed to fn
.
\returns an opaque pointer to the new thread object on success, NULL if the
new thread could not be created; call SDL_GetError() for more
information.
\since This function is available since SDL 3.1.3.
\sa SDL_CreateThreadWithProperties \sa SDL_WaitThread
extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
Implementation
Pointer<SdlThread> sdlCreateThread(
Pointer<NativeFunction<SdlThreadFunction>> fn,
String? name,
Pointer<NativeType> data) {
final sdlCreateThreadLookupFunction = libSdl3.lookupFunction<
Pointer<SdlThread> Function(Pointer<NativeFunction<SdlThreadFunction>> fn,
Pointer<Utf8> name, Pointer<NativeType> data),
Pointer<SdlThread> Function(Pointer<NativeFunction<SdlThreadFunction>> fn,
Pointer<Utf8> name, Pointer<NativeType> data)>('SDL_CreateThread');
final namePointer = name != null ? name.toNativeUtf8() : nullptr;
final result = sdlCreateThreadLookupFunction(fn, namePointer, data);
calloc.free(namePointer);
return result;
}