fix case new thread is created from thread that never had a thread installed

This commit is contained in:
Vítor Santos Costa 2013-09-17 00:26:37 +01:00
parent 5ea258f885
commit 1eab4bc936
2 changed files with 21 additions and 4 deletions

View File

@ -1155,6 +1155,14 @@ Yap_InitThread(int new_id)
if (!(new_s = (struct worker_local *)calloc(sizeof(struct worker_local), 1)))
return FALSE;
Yap_local[new_id] = new_s;
if (!((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))) {
REGSTORE *rs = (REGSTORE *)calloc(sizeof(REGSTORE),1);
pthread_setspecific(Yap_yaamregs_key, (const void *)rs);
REMOTE_ThreadHandle(new_id).default_yaam_regs = rs;
REMOTE_ThreadHandle(new_id).current_yaam_regs = REMOTE_ThreadHandle(new_id).default_yaam_regs;
rs->worker_id_ = new_id;
rs->worker_local_ = REMOTE(new_id);
}
}
InitWorker(new_id);
return TRUE;

View File

@ -94,15 +94,24 @@ store_specs(int new_worker_id, UInt ssize, UInt tsize, UInt sysize, Term *tpgoal
REMOTE_ThreadHandle(new_worker_id).ssize = ssize;
REMOTE_ThreadHandle(new_worker_id).tsize = tsize;
REMOTE_ThreadHandle(new_worker_id).sysize = sysize;
REMOTE_c_input_stream(new_worker_id) = LOCAL_c_input_stream;
REMOTE_c_output_stream(new_worker_id) = LOCAL_c_output_stream;
REMOTE_c_error_stream(new_worker_id) = LOCAL_c_error_stream;
if ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key)) {
REMOTE_c_input_stream(new_worker_id) = LOCAL_c_input_stream;
REMOTE_c_output_stream(new_worker_id) = LOCAL_c_output_stream;
REMOTE_c_error_stream(new_worker_id) = LOCAL_c_error_stream;
} else {
// thread is created by a thread that has never run Prolog
REMOTE_c_input_stream(new_worker_id) = REMOTE_c_input_stream(0);
REMOTE_c_output_stream(new_worker_id) = REMOTE_c_output_stream(0);
REMOTE_c_error_stream(new_worker_id) = REMOTE_c_error_stream(0);
}
pm = (ssize + tsize)*1024;
if (!(REMOTE_ThreadHandle(new_worker_id).stack_address = malloc(pm))) {
return FALSE;
}
REMOTE_ThreadHandle(new_worker_id).tgoal =
Yap_StoreTermInDB(Deref(*tpgoal),7);
Yap_StoreTermInDB(Deref(*tpgoal), 7);
REMOTE_ThreadHandle(new_worker_id).cmod =
CurrentModule;
tdetach = Deref(*tpdetach);