Forked GC explained
frame
frame86 at live.com
Mon Sep 5 11:12:38 UTC 2022
On Saturday, 3 September 2022 at 14:31:31 UTC, Steven
Schveighoffer wrote:
> On 9/3/22 9:35 AM, frame wrote:
>> What happens if a manually `GC.free()` is called while the
>> forked process marks the memory as free too but the GC
>> immediately uses the memory again and then gets the
>> notification to free it from the forked child? Can this happen?
>
> No, because if you can free it, you should have had a reference
> to it when you forked, which should mean it's not garbage.
And what if the programmer has no actual reference but wrongly
forced a `free()` through a pointer cast?
```
| OP | Memory M
-------------------------------------------
Parent: | - | Unreferenced, marked in use
-------------------------------------------
Parent: | fork
-------------------------------------------
Parent: | - | Unreferenced, marked in use
Child: | | Unreferenced, marked in use
-------------------------------------------
Parent: | - | Unreferenced, marked in use
Child: | | Unreferenced, found M
-------------------------------------------
Parent: | free | Unreferenced, marked not in use <- error
forced by programmer
Child: | | Unreferenced, found M
-------------------------------------------
Parent: | new | Referenced, re-used because it was marked free
Child: | | Unreferenced, found M
-------------------------------------------
Parent: | - | Referenced, used
Child: | | Done scanning. Please collect: M
-------------------------------------------
Parent: | collect | M
Child: | | exit
-------------------------------------------
```
@wjoe is the GC aware of this to exclude M from the child result
set because it has changed while the child was running?
> There's a talk on it from the 2013 dconf by the inventor:
> https://dconf.org/2013/talks/lucarella.html
>
> -Steve
Thanks for the link. The slides mentioning shared memory.
More information about the Digitalmars-d-learn
mailing list