c return value through parameters -
so, i'm puzzled issue on hour.
background:
i have implementation of kernel threads in xv6 want test.
the threads communicate return values via field ret_val.
each thread saves return value in the other thread's ret_val (because can technically de-allocated after returning value).
i have 2 parts in code not work i'd expect.
*notes: field proc->ret_val of type void** field proc->has_waiting of type struct proc *
part 1 (this part stores return value in process's struct):
// store value in waiting thread's ret_val. (*proc->has_waiting->ret_val) = (void*)ret_val; cprintf("(t_exit)process %d taking return value %s\n", proc->pid, (char *)ret_val); cprintf("(t_exit)process %d has return value %d -> %s\n", proc->has_waiting->pid, proc->pid, (char *)(*proc->has_waiting->ret_val));
this ^ part's job store value in process's ret_val (inside "has_waiting" field, pointer structure of process).
this seems work because prints indicate value indeed saved.
part 2 (this part tries read process's struct ret_val field):
cprintf("(t_join) process %d taking return value %s\n", proc->pid, (char *)(*proc->ret_val)); * ret_val = proc->ret_val; // it's t's duty set proc's ret_val
this ^ part's job restore value within struct's structure (ret_val field) before it's destroyed.
part 2 not work, ret_val field empty.
i've tried sorts of casting manipulations seems misunderstand basic concept here.
i've verified struct i'm addressing correct struct printing out it's id (unique).
the value i'm passing (in ret_val) static string (char*) i've defined in main function creates processes (i wanted make sure it's not destroyed or something).
i'd appreciate help. if further information needed let me know.
if reading correctly, "return" value via field:
proc->has_waiting->ret_val
but reference via field:
proc->ret_val
you should using same reference in both places.
edit: how simplifying , making ret_val
char *
?
Comments
Post a Comment