http://www.aros.orgAROS-ExecAROS-Exec ArchivesPower2People
kitty mascottop logo menu

pointer Home

bullet

czech logo Česky

bullet

germany logo Deutsch

bullet

greece logo Ελληυικά

bullet

english logo English

bullet

spanish logo Español

bullet

france logo Français

bullet

italy logo Italiano

bullet

netherlands logo Nederlands

bullet

poland logo Polski

bullet

portugal logo Português

bullet

russian logo Русский

bullet

finland logo Suomi

bullet

sweden logo Svenska


pointer Uutiset

bullet Arkisto

pointer Esittely

bullet Tilanne
bullet Ruutukaappauksia
bullet Porttaukset
bullet Lisenssi

pointer Imuroi


pointer Dokumentaatio

bullet Käyttäjät
bullet Asennus
bullet Käyttö
bullet Shell commands
bullet Applications
bullet FAQ
bullet HowTo
bullet Hardware Compatibility
bullet Kehittäjät
bullet Osanotto
bullet Roadmap
bullet Bugien seuranta
bullet Subversion:n kanssa työskentely
bullet Kääntö
bullet Ohjelmiston kehitysmanuaali
bullet Zune-ohjelmiston kehitysmanuaali
bullet Järjestelmän kehitysmanuaali
bullet Debuggaus opas
bullet Referenssit
bullet Spesifikaatioita
bullet UI tyyliopas
bullet Dokumentointi
bullet Porting
bullet Tulkitseminen
bullet Yhteenvetoja
bullet Linkkejä

pointer Yhteyden otto

bullet Postituslistat
bullet IRC kanavat

pointer Ansiot

pointer Acknowledgements


pointer Kuvia

bullet Kehittäjät
bullet Kehittäjät yhdessä

pointer Tukijat

pointer Linkit toisaalta

pointer Linkkejä

www.hepe.com
Trustsec
Genesi USA
Get AROS Research Operating System at SourceForge.net. Fast, secure and Free Open Source software downloads
No EU patents

thread

Index


BroadcastCondition() CreateCondition() CreateMutex() CreateThread()
CurrentThread() DestroyCondition() DestroyMutex() DetachThread()
ExitThread() LockMutex() SignalCondition() TryLockMutex()
UnlockMutex() WaitAllThreads() WaitCondition() WaitThread()

BroadcastCondition()

Synopsis

void BroadcastCondition(
         void * cond );

Function

Signals all threads waiting on a condition variable.

Inputs

cond - the condition to signal.

Result

This function always succeeds.

Example

LockMutex(mutex);
BroadcastCondition(cond);
UnlockMutex(mutex);

Notes

Before calling this function you should lock the mutex that protects
the condition. WaitCondition() atomically unlocks the mutex and waits
on the condition, so by locking the mutex first before sending the
signal, you ensure that the signal cannot be missed. See
WaitCondition() for more details.

If no threads are waiting on the condition, nothing happens.

CreateCondition()

Synopsis

void * CreateCondition();

Function

Creates a condition variable.

Inputs

None.

Result

The newly created condition, or NULL if one couldn't be created.

Notes

Condition cond = CreateCondition();

CreateMutex()

Synopsis

void * CreateMutex();

Function

Creates a mutual exclusion device (aka lock).

Inputs

None.

Result

The newly created mutex, or NULL if a mutex couldn't be created.

Example

Mutex mutex = CreateMutex();

CreateThread()

Synopsis

uint32_t CreateThread(
         ThreadEntryFunction entry,
         void * data );

Function

Creates a new thread.

Inputs

entry - pointer to a function to run in the new thread
data  - pointer to pass in the first in the first argument to function
        pointed to by entry

Result

Numeric thread ID, or 0 if the thread could not be started.

Example

uint32_t id = CreateThread(entry, data);
if (id < 0)
    printf("thread creation failed\n");
else
    printf("thread %d created\n", id);

CurrentThread()

Synopsis

uint32_t CurrentThread();

Function

Get the ID of the running thread.

Inputs

None.

Result

Numeric thread ID, or 0 if this is not a thread.

Example

uint32_t id = CurrentThread();
printf("this is thread %d\n", id);

DestroyCondition()

Synopsis

BOOL DestroyCondition(
         void * cond );

Function

Destroys a condition variable.

Inputs

cond - the condition variable to destroy.

Result

TRUE if the condition was destroyed, otherwise FALSE.

Example

DestroyCondition(cond);

Notes

You cannot destroy a condition variable if other threads are waiting on
it.

DestroyMutex()

Synopsis

BOOL DestroyMutex(
         void * mutex );

Function

Destroys a mutex.

Inputs

mutex - the mutex to destroy.

Result

TRUE if the mutex was destroyed, otherwise FALSE.

Example

DestroyMutex(mutex)

Notes

You cannot destroy a mutex that is currently locked or has tasks
waiting to lock it.

DetachThread()

Synopsis

BOOL DetachThread(
         uint32_t thread_id );

Function

Detaches a thread from the parent process.

Inputs

thread_id - ID of thread to detach.

Result

TRUE if the thread was detached, FALSE if the thread was already
detached or another error occured.

Example

DetachThread(id);

Notes

You cannot detach a thread that is already detached.

Once detached, the thread is no longer accessible from any other
thread.

Bugs

Currently this doesn't really do anything other than make it so you
can't call WaitThread() on the thread. Threads can't truly be detached
from the parent process since they run in the same address space, and
so when the process exits the program code and all its other resources
a freed.

thread.library protects against this by waiting for all threads to
complete (detached or not) before allowing the main process to exit.

Detached threads can't be truly implemented until a thread task and its
allocated resources can exist independently of the process that created
it.

ExitThread()

Synopsis

void ExitThread(
         void * result );

Function

Exits the calling thread.

Inputs

result    - pointer to storage for the thread's return value. You can
            pass NULL here if you don't care about the return value.

Result

None, this function never returns.

Example

ExitThread(5);

Notes

This function is similar to the exit() function of arosc library.

LockMutex()

Synopsis

void LockMutex(
         void * mutex );

Function

Locks a mutex. If the lock is already held, this function blocks.

Inputs

mutex - mutex to lock.

Result

This function always succeeds.

Example

LockMutex(mutex);

SignalCondition()

Synopsis

void SignalCondition(
         void * cond );

Function

Signals a thread waiting on condition variable.

Inputs

cond - the condition to signal.

Result

This function always succeeds.

Example

LockMutex(mutex);
SignalCondition(cond);
UnlockMutex(mutex);

Notes

Before calling this function you should lock the mutex that protects
the condition. WaitCondition() atomically unlocks the mutex and waits
on the condition, so by locking the mutex first before sending the
signal, you ensure that the signal cannot be missed. See
WaitCondition() for more details.

If no threads are waiting on the condition, nothing happens. If more
than one thread is waiting, only one will be signalled. Which one is
undefined.

TryLockMutex()

Synopsis

BOOL TryLockMutex(
         void * mutex );

Function

Tries to lock a mutex. If the lock is already held, this function
fails.

Inputs

mutex - mutex to lock.

Result

TRUE if the lock was acquired, FALSE if the lock is already held.

Example

TryLockMutex(mutex);

UnlockMutex()

Synopsis

void UnlockMutex(
         void * mutex );

Function

Unlocks a locked mutex.

Inputs

mutex - mutex to unlock.

Result

This function always succeeds.

Example

UnlockMutex(mutex);

WaitAllThreads()

Synopsis

void WaitAllThreads();

Function

Blocks the current task until all threads exit.

Inputs

None.

Result

This function always succeeds.

Example

WaitAllThreads();

Notes

This function will ignore detached threads.

WaitCondition()

Synopsis

BOOL WaitCondition(
         void * cond,
         void * mutex );

Function

Blocks until a condition is signaled.

Inputs

cond - the condition variable to wait on.
mutex - a mutex that protects the condition

Result

TRUE if the condition was signaled, FALSE if an error occured.

Example

LockMutex(mutex);
WaitCondition(cond, mutex);
UnlockMutex(mutex);

Notes

This function will atomically unlock the mutex and wait on the
condition. The thread is suspended until the condition is signalled.
After the condition is signalled, the mutex is relocked before
returning to the caller.

The use of a mutex in conjunction with waiting on and signalling the
condition ensures that no signals are missed. See SignalCondition() for
more details.

WaitThread()

Synopsis

BOOL WaitThread(
         uint32_t thread_id,
         void ** result );

Function

Blocks the current task until the requested thread exits.

Inputs

thread_id - ID of thread to detach.
result    - pointer to storage for the thread's return value. You can
            pass NULL here if you don't care about the return value.

Result

TRUE when the thread completed successfully. FALSE if thread could not
be waited on.

Example

void *ret;
WaitThread(id, &ret);

Notes

A thread cannot wait on itself. A thread cannot be waited on if it is
detached.

If the thread has already completed, this call returns immediately with
the thread result. Further calls to this function for that thread will
fail.

Multiple threads can wait for a thread to complete. They will all
be notified when the thread completes, and will all receive the result.

Copyright © 1995-2012, The AROS Development Team. All rights reserved.
Amiga®, AmigaOS®, Workbench and Intuition are trademarks of Amiga Inc. All other trademarks belong to their respective owners.