4 ms·
> You should be able to know all the references to a variable, if you are careful when writing your program. The issue is: what if thread A and thread B hold a
by acatton 4y ago
> You should be able to know all the references to a variable, if you are careful when writing your program.
The issue is: what if thread A and thread B hold a reference to the password variable? And you don't know in which order they will execute. In which thread do you scramble the password before releasing the variable reference?
From what I understand, OP's point is: because of the nature of C, you have to know where your variable is "free()ed", because you have to do it yourself. Therefore you can scramble there. Even if you have two thread doing:
n = decr_reference(password)
if (n == 0) {
scramble(password)
free(password)
}
- nebulous1 4y agoThat issue seems the same in a GC language as it is in a non-GC one. Either way you need to know when you're done with the data and it's time to scramble.
- aflag 4y agoOne possibility would be to reference a password variable always from t he same thread. But even if you use multiple threads referencing the same memory location, you could make some of them weak references (which the GC doesn't take into account when deleting the object) or you could make sure you stop referencing them in both threads and force the GC to run on that object. The destructor could handle the scrambling.
- deleted 4y ago[deleted]