Package ch.bailu.gtk.glib
Klasse Thread
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Thread
- Alle implementierten Schnittstellen:
PointerInterface
The #GThread struct represents a running thread. This struct
is returned by g_thread_new() or g_thread_try_new(). You can
obtain the #GThread struct representing the current thread by
calling g_thread_self().
GThread is refcounted, see g_thread_ref() and g_thread_unref().
The thread represented by it holds a reference while it is running,
and g_thread_join() consumes the reference that it is given, so
it is normally not necessary to manage GThread references
explicitly.
The structure is opaque -- none of its fields may be directly
accessed.
is returned by g_thread_new() or g_thread_try_new(). You can
obtain the #GThread struct representing the current thread by
calling g_thread_self().
GThread is refcounted, see g_thread_ref() and g_thread_unref().
The thread represented by it holds a reference while it is running,
and g_thread_join() consumes the reference that it is given, so
it is normally not necessary to manage GThread references
explicitly.
The structure is opaque -- none of its fields may be directly
accessed.
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic interface
static interface
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungThread()
Thread
(PointerContainer pointer) Thread
(Str name, Thread.OnThreadFunc func, Pointer data) This function creates a new thread.Thread
(String name, Thread.OnThreadFunc func, Pointer data) This function creates a new thread. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic Thread
create
(Thread.OnThreadFunc func, Pointer data, boolean joinable) Veraltet.static Thread
createFull
(Thread.OnThreadFunc func, Pointer data, long stack_size, boolean joinable, boolean bound, int priority) Veraltet.static int
static void
Terminates the current thread.static void
foreach
(Thread.OnFunc thread_func, Pointer user_data) Veraltet.static ClassHandler
ch.bailu.gtk.glib.JnaThread.OnThreadFunc
boolean
int
static boolean
Indicates if g_thread_init() has been called.static int
getName()
Gets the name of the thread.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
static void
Veraltet.static void
initWithErrorcheckMutexes
(Pointer vtable) join()
Waits until @thread finishes, i.e. the function @func, as
given to g_thread_new(), returns or g_thread_exit() is called.ref()
Increase the reference count on @thread.static Thread
self()
This function returns the #GThread corresponding to the
current thread.void
void
setPriority
(int priority) Veraltet.static Thread
tryNewThread
(Str name, Thread.OnThreadFunc func, Pointer data) This function is the same as g_thread_new() except that
it allows for the possibility of failure.static Thread
tryNewThread
(String name, Thread.OnThreadFunc func, Pointer data) This function is the same as g_thread_new() except that
it allows for the possibility of failure.void
unref()
Decrease the reference count on @thread, possibly freeing all
resources associated with it.static void
yield()
Causes the calling thread to voluntarily relinquish the CPU, so
that other threads can run.Von Klasse geerbte Methoden ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Von Klasse geerbte Methoden ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Von Klasse geerbte Methoden java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Von Schnittstelle geerbte Methoden ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Felddetails
-
FUNC
- Siehe auch:
-
DATA
- Siehe auch:
-
JOINABLE
- Siehe auch:
-
PRIORITY
- Siehe auch:
-
-
Konstruktordetails
-
Thread
-
Thread
public Thread() -
Thread
This function creates a new thread. The new thread starts by invoking
@func with the argument data. The thread will run until @func returns
or until g_thread_exit() is called from the new thread. The return value
of @func becomes the return value of the thread, which can be obtained
with g_thread_join().
The @name can be useful for discriminating threads in a debugger.
It is not used for other purposes and does not have to be unique.
Some systems restrict the length of @name to 16 bytes.
If the thread can not be created the program aborts. See
g_thread_try_new() if you want to attempt to deal with failures.
If you are using threads to offload (potentially many) short-lived tasks,
#GThreadPool may be more appropriate than manually spawning and tracking
multiple #GThreads.
To free the struct returned by this function, use g_thread_unref().
Note that g_thread_join() implicitly unrefs the #GThread as well.
New threads by default inherit their scheduler policy (POSIX) or thread
priority (Windows) of the thread creating the new thread.
This behaviour changed in GLib 2.64: before threads on Windows were not
inheriting the thread priority but were spawned with the default priority.
Starting with GLib 2.64 the behaviour is now consistent between Windows and
POSIX and all threads inherit their parent thread's priority.- Parameter:
name
- an (optional) name for the new threadfunc
- a function to execute in the new threaddata
- an argument to supply to the new thread
-
Thread
This function creates a new thread. The new thread starts by invoking
@func with the argument data. The thread will run until @func returns
or until g_thread_exit() is called from the new thread. The return value
of @func becomes the return value of the thread, which can be obtained
with g_thread_join().
The @name can be useful for discriminating threads in a debugger.
It is not used for other purposes and does not have to be unique.
Some systems restrict the length of @name to 16 bytes.
If the thread can not be created the program aborts. See
g_thread_try_new() if you want to attempt to deal with failures.
If you are using threads to offload (potentially many) short-lived tasks,
#GThreadPool may be more appropriate than manually spawning and tracking
multiple #GThreads.
To free the struct returned by this function, use g_thread_unref().
Note that g_thread_join() implicitly unrefs the #GThread as well.
New threads by default inherit their scheduler policy (POSIX) or thread
priority (Windows) of the thread creating the new thread.
This behaviour changed in GLib 2.64: before threads on Windows were not
inheriting the thread priority but were spawned with the default priority.
Starting with GLib 2.64 the behaviour is now consistent between Windows and
POSIX and all threads inherit their parent thread's priority.- Parameter:
name
- an (optional) name for the new threadfunc
- a function to execute in the new threaddata
- an argument to supply to the new thread
-
-
Methodendetails
-
getClassHandler
-
setFieldFunc
-
getFieldFunc
public ch.bailu.gtk.glib.JnaThread.OnThreadFunc getFieldFunc() -
getFieldData
-
getFieldJoinable
public boolean getFieldJoinable() -
getFieldPriority
public int getFieldPriority() -
tryNewThread
public static Thread tryNewThread(@Nullable Str name, Thread.OnThreadFunc func, @Nullable Pointer data) throws AllocationError This function is the same as g_thread_new() except that
it allows for the possibility of failure.
If a thread can not be created (due to resource limits),
@error is set and %NULL is returned.- Parameter:
name
- an (optional) name for the new threadfunc
- a function to execute in the new threaddata
- an argument to supply to the new thread- Gibt zurück:
- the new #GThread, or %NULL if an error occurred
- Löst aus:
AllocationError
-
tryNewThread
public static Thread tryNewThread(String name, Thread.OnThreadFunc func, @Nullable Pointer data) throws AllocationError This function is the same as g_thread_new() except that
it allows for the possibility of failure.
If a thread can not be created (due to resource limits),
@error is set and %NULL is returned.- Parameter:
name
- an (optional) name for the new threadfunc
- a function to execute in the new threaddata
- an argument to supply to the new thread- Gibt zurück:
- the new #GThread, or %NULL if an error occurred
- Löst aus:
AllocationError
-
getName
Gets the name of the thread.
This function is intended for debugging purposes.- Gibt zurück:
- the name of the thread
-
join
Waits until @thread finishes, i.e. the function @func, as
given to g_thread_new(), returns or g_thread_exit() is called.
If @thread has already terminated, then g_thread_join()
returns immediately.
Any thread can wait for any other thread by calling g_thread_join(),
not just its 'creator'. Calling g_thread_join() from multiple threads
for the same @thread leads to undefined behaviour.
The value returned by @func or given to g_thread_exit() is
returned by this function.
g_thread_join() consumes the reference to the passed-in @thread.
This will usually cause the #GThread struct and associated resources
to be freed. Use g_thread_ref() to obtain an extra reference if you
want to keep the GThread alive beyond the g_thread_join() call.- Gibt zurück:
- the return value of the thread
-
ref
Increase the reference count on @thread.- Gibt zurück:
- a new reference to @thread
-
setPriority
Veraltet.This function does nothing.- Parameter:
priority
- ignored
-
unref
public void unref()Decrease the reference count on @thread, possibly freeing all
resources associated with it.
Note that each thread holds a reference to its #GThread while
it is running, so it is safe to drop your own reference to it
if you don't need it anymore. -
create
@Deprecated public static Thread create(Thread.OnThreadFunc func, @Nullable Pointer data, boolean joinable) throws AllocationError Veraltet.This function creates a new thread.
The new thread executes the function @func with the argument @data.
If the thread was created successfully, it is returned.
@error can be %NULL to ignore errors, or non-%NULL to report errors.
The error is set, if and only if the function returns %NULL.
This function returns a reference to the created thread only if
@joinable is %TRUE. In that case, you must free this reference by
calling g_thread_unref() or g_thread_join(). If @joinable is %FALSE
then you should probably not touch the return value.- Parameter:
func
- a function to execute in the new threaddata
- an argument to supply to the new threadjoinable
- should this thread be joinable?- Gibt zurück:
- the new #GThread on success
- Löst aus:
AllocationError
-
createFull
@Deprecated public static Thread createFull(Thread.OnThreadFunc func, @Nullable Pointer data, long stack_size, boolean joinable, boolean bound, int priority) throws AllocationError Veraltet.This function creates a new thread.- Parameter:
func
- a function to execute in the new thread.data
- an argument to supply to the new thread.stack_size
- a stack size for the new thread.joinable
- should this thread be joinable?bound
- ignoredpriority
- ignored- Gibt zurück:
- the new #GThread on success.
- Löst aus:
AllocationError
-
errorQuark
public static int errorQuark()- Gibt zurück:
-
exit
Terminates the current thread.
If another thread is waiting for us using g_thread_join() then the
waiting thread will be woken up and get @retval as the return value
of g_thread_join().
Calling g_thread_exit() with a parameter @retval is equivalent to
returning @retval from the function @func, as given to g_thread_new().
You must only call g_thread_exit() from a thread that you created
yourself with g_thread_new() or related APIs. You must not call
this function from a thread created with another threading library
or or from within a #GThreadPool.- Parameter:
retval
- the return value of this thread
-
foreach
Veraltet.Call @thread_func on all #GThreads that have been
created with g_thread_create().
Note that threads may decide to exit while @thread_func is
running, so without intimate knowledge about the lifetime of
foreign threads, @thread_func shouldn't access the GThread*
pointer passed in as first argument. However, @thread_func will
not be called for threads which are known to have exited already.
Due to thread lifetime checks, this function has an execution complexity
which is quadratic in the number of existing threads.- Parameter:
thread_func
- function to call for all #GThread structuresuser_data
- second argument to @thread_func
-
getInitialized
public static boolean getInitialized()Indicates if g_thread_init() has been called.- Gibt zurück:
- %TRUE if threads have been initialized.
-
init
Veraltet.If you use GLib from more than one thread, you must initialize the
thread system by calling g_thread_init().
Since version 2.24, calling g_thread_init() multiple times is allowed,
but nothing happens except for the first call.
Since version 2.32, GLib does not support custom thread implementations
anymore and the @vtable parameter is ignored and you should pass %NULL.
::: note
g_thread_init() must not be called directly or indirectly in a
callback from GLib. Also no mutexes may be currently locked
while calling g_thread_init().
::: note
To use g_thread_init() in your program, you have to link with
the libraries that the command `pkg-config --libs gthread-2.0`
outputs. This is not the case for all the other thread-related
functions of GLib. Those can be used without having to link
with the thread libraries.- Parameter:
vtable
- a function table of type #GThreadFunctions, that provides the entry points to the thread system to be used. Since 2.32, this parameter is ignored and should always be %NULL
-
initWithErrorcheckMutexes
- Parameter:
vtable
-
-
self
This function returns the #GThread corresponding to the
current thread. Note that this function does not increase
the reference count of the returned struct.
This function will return a #GThread even for threads that
were not created by GLib (i.e. those created by other threading
APIs). This may be useful for thread identification purposes
(i.e. comparisons) but you must not use GLib functions (such
as g_thread_join()) on these threads.- Gibt zurück:
- the #GThread representing the current thread
-
yield
public static void yield()Causes the calling thread to voluntarily relinquish the CPU, so
that other threads can run.
This function is often used as a method to make busy wait less evil. -
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-