NAME ^

src/thread.c - Thread handling stuff

DESCRIPTION ^

Threads are created by creating new ParrotInterpreter objects.

Functions ^

make_local_copy

Create a local copy of the PMC if necessary. (No copy is made if it is marked shared.) This includes workarounds for Parrot_clone() not doing the Right Thing with subroutines (specifically, code segments aren't preserved and it is difficult to do so as long as Parrot_clone() depends on freezing).

make_local_args_copy

Make a local copy of the corresponding array of arguments.

pt_shared_fixup

Fixup a PMC to be sharable. Right now, reassigns the vtable to one owned by some master interpreter, so the PMC can be safely reused after thread death.

In the future the PMC returned might be different than the one passed, e.g., if we need to reallocate the PMC in a different interpreter.

pt_thread_signal

Wakeup a interp which should have called pt_thread_wait().

pt_thread_wait_with

Wait for this interpreter to be signalled through its condition variable, dealing properly with GC issues. *mutex is assumed locked on entry and will be locked on exit from this function. If a GC run occurs in the middle of this function, then a spurious wakeup may occur.

pt_thread_wait

Wait for us to be signalled. GC matters are handled correctly. interpreter_array_mutex is assumed held. Spurious wakeups may occur.

thread_func

The actual thread function.

Helper functions used also for running plain interpreters ^

pt_clone_code

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

pt_thread_prepare_for_run

Setup code, and TODO ...

ParrotThread methods ^

pt_thread_run

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

arg should be an array of arguments for the subroutine.

pt_thread_run_1

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

pt_thread_run_2

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

pt_thread_run_3

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

pt_thread_yield

Relinquishes hold on the processor.

pt_check_tid

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

mutex_unlock

Unlocks the mutex *arg.

is_suspended_for_gc

Returns true iff interp is suspended so a global GC can be performed. interpreter_array_mutex must be held.

pt_suspend_one_for_gc

Suspend a single interpreter for GC. interpreter_array_mutex assumed held.

pt_suspend_all_for_gc

Get all threads to perform a GC run.

pt_suspend_self_for_gc

Suspend this thread for a full GC run.

XXX FIXME -- if GC is blocked, we need to do a GC run as soon as it becomes unblocked.

pt_thread_join

Join (wait for) a joinable thread.

pt_join_threads

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

detach

Helper for detach and kill.

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

pt_thread_detach

Detaches (make non-joinable) the thread.

pt_thread_kill

Kills the thread.

Threaded interpreter book-keeping ^

pt_add_to_interpreters

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

DOD Synchronization Functions ^

pt_DOD_start_mark

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.

flags are the DOD flags. We check if we need to collect shared objects or not.

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.

pt_DOD_mark_root_finished

DOD is finished for the root set.

pt_DOD_stop_mark

DOD's mark phase is done.

Parrot_shared_DOD_block

Block stop-the-world DOD runs.

Parrot_shared_DOD_unblock

Unblock stop-the-world DOD runs.


parrot