diff --git a/gc-notes.txt b/gc-notes.txt index c36bbd08..98014d9c 100644 --- a/gc-notes.txt +++ b/gc-notes.txt @@ -12,6 +12,9 @@ TODO: - multiple mutators, and threading functions/types. probably want this on a new branch, when ready part of this is implementing the beginnings of srfi-18, to create multiple threads, sync them, etc + TODO items: + - lock writes to symbol table + - need to cooperate when a mutator is blocked might be able to stop a thread and do a minor GC on it, but no longjmp until after major GC. would need to figure out how to repack gc_cont and args diff --git a/gc.c b/gc.c index 2c0b7150..cc174ee8 100644 --- a/gc.c +++ b/gc.c @@ -1220,6 +1220,8 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *)); thd->stack_trace_idx = 0; thd->stack_prev_frame = NULL; +// thd->thread = NULL; + thd->thread_state = CYC_THREAD_STATE_NEW; //thd->mutator_num = mut_num; thd->jmp_start = malloc(sizeof(jmp_buf)); thd->gc_args = malloc(sizeof(object) * NUM_GC_ANS); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 9ba3b8da..d88b557e 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -47,9 +47,18 @@ /* Define general object type. */ typedef void *object; +/* Threading */ +typedef enum { CYC_THREAD_STATE_NEW + , CYC_THREAD_STATE_RUNNABLE + , CYC_THREAD_STATE_TERMINATED + } cyc_thread_state_type; + /* Thread data structures */ typedef struct gc_thread_data_t gc_thread_data; struct gc_thread_data_t { +// TODO: +// pthread_t *thread; + cyc_thread_state_type thread_state; // Data needed to initiate stack-based minor GC char *stack_start; char *stack_limit; diff --git a/runtime.c b/runtime.c index d695abbe..578daba6 100644 --- a/runtime.c +++ b/runtime.c @@ -2491,6 +2491,9 @@ TODO: should rename this function to make it more clear what is really going on */ void Cyc_start_thread(gc_thread_data *thd) { +// TODO: should use an atomic set to modify this + thd->thread_state = CYC_THREAD_STATE_RUNNABLE; + /* Tank, load the jump program... */ setjmp(*(thd->jmp_start)); @@ -3141,6 +3144,9 @@ void *Cyc_init_thread(object thunk) thd->gc_cont = thunk; thd->gc_num_args = 1; thd->gc_args[0] = &Cyc_91end_91thread_67_primitive; +// thd->thread = pthread_self(); // TODO: ptr vs instance +// returns instance so would need to malloc here +// would also need to update termination code to free that memory gc_add_mutator(thd); Cyc_start_thread(thd); return NULL; @@ -3193,6 +3199,8 @@ void Cyc_end_thread(gc_thread_data *thd) // referenced? might want to do one more minor GC to clear the stack before // terminating the thread +// TODO: use ATOMIC set to modify this + thd->thread_state = CYC_THREAD_STATE_TERMINATED; pthread_exit(NULL); // For now, just a proof of concept }