Lab 3 - IDA
Lab 3 - IDA
Lab 3 - IDA
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Reference counting<br />
“poor man's garbage collector”<br />
• Parent – Child needs a new data structure<br />
• Who will free this memory depends on who exits last<br />
• Many ways to implement this. Suggestion: you can use<br />
reference counting:<br />
– struct child_status{<br />
int exit_status;<br />
/* ... */<br />
int ref_cnt;<br />
};<br />
child<br />
– /* Initialize it */<br />
struct child_status * cs = malloc ... ;<br />
cs>ref_cnt = 2; /* both parent and child live */<br />
cs<br />
parent<br />
– /* When parent or child is done with cs: */<br />
cs>ref_cnt; /* Needs to be protected by a lock */<br />
if ( cs>ref_cnt == 0 ){ free( cs ); }<br />
17