NAME ^

src/thread.c - Thread handling stuff

DESCRIPTION ^

Threads are created by creating new ParrotInterpreter objects.

Functions ^

static void *thread_func(void *arg)

The actual thread function.

Helper functions used also for running plain interpreters ^

void pt_clone_code(Parrot_Interp d, Parrot_Interp s)

Copy/clone the packfile/code from interpreter s to d. All resources are created in d.

void pt_thread_prepare_for_run(Parrot_Interp d, Parrot_Interp s)

Setup code, and TODO ...

ParrotThread methods ^

int pt_thread_run(Parrot_Interp interp, PMC *dest_interp, PMC *sub)

Run the *sub PMC in a separate thread using interpreter in *dest_interp.

int pt_thread_run_1(Parrot_Interp interp, PMC *dest_interp, PMC *sub)

Runs a type 1 thread. Nothing is shared, both interpreters are free running without any communication.

int pt_thread_run_2(Parrot_Interp interp, PMC *dest_interp, PMC *sub)

Runs a type 2 thread. No shared variables, threads are communicating by sending messages.

int pt_thread_run_3(Parrot_Interp interp, PMC *dest_interp, PMC *sub)

Run a type 3 thread. Threads may have shared variables and are managed in a thread pool.

void pt_thread_yield(void)

Relinquishes hold on the processor.

static Parrot_Interp pt_check_tid(UINTVAL tid, const char *from)

Helper function. Check if tid is valid. The caller holds the mutex. Returns the interpreter for tid.

static void mutex_unlock(void *arg)

Unlocks the mutex *arg.

void *pt_thread_join(Parrot_Interp parent, UINTVAL tid)

Join (wait for) a joinable thread.

void pt_join_threads(Parrot_Interp interpreter)

Possibly wait for other running threads. This is called when destroying interpreter.

static Parrot_Interp detach(UINTVAL tid)

Helper for detach and kill.

Returns the interpreter, if it didn't finish yet.

void pt_thread_detach(UINTVAL tid)

Detaches (make non-joinable) the thread.

void pt_thread_kill(UINTVAL tid)

Kills the thread.

Threaded interpreter book-keeping ^

void pt_add_to_interpreters(Parrot_Interp interpreter, Parrot_Interp new_interp)

All threaded interpreters are stored in an array. Assumes that caller holds LOCK.

DOD Synchronization Functions ^

void pt_DOD_start_mark(Parrot_Interp interpreter)

DOD is gonna start the mark phase. In the presence of shared PMCs, we can only run one DOD run at a time because PMC->next_for_GC may be changed.

TODO - Have a count of shared PMCs and check it during DOD.

TODO - Evaluate, if a interpreter lock is cheaper, when dod_mark_ptr is updated.

void pt_DOD_mark_root_finished(Parrot_Interp interpreter)

DOD is finished for the root set.

void pt_DOD_stop_mark(Parrot_Interp interpreter)

DOD's mark phase is done.

HISTORY ^

2003.12.18 leo initial rev

SEE ALSO ^

src/pmc/parrotinterpreter.pmc, docs/dev/events.pod.


parrot