Message374939
As per Guido's comment (https://github.com/python/cpython/pull/21516#issuecomment-668110711), I'm going to use this space to discuss ways to go forward with resource tracking and SharedMemory.
Taking inspiration from Vinay (https://bugs.python.org/issue37754#msg351445), I think the simplest and best way forward is to use a small section of the shared memory at the start as a reference counter.
Every time a process latches onto a shared memory block, it does and atomic increment to the reference counter. And if it detaches, it does an atomic decrement. This atomic operations are available in C via hardware specific instructions. This would require modifying the Python C code posixshmem.c. It should not be a difficult change.
This would then change the SharedMemory API such that a call to `close()` could check the reference count at the end, and aromatically unlink if it reaches 0. Basically, the purpose of the explicit `unlink()` call is dissolved.
I think this would also play nice with the current implementation of the `resource_tracker`. A small change would need to take place such that it calls `close()` instead of `unlink()` as the clean up function. Nonetheless, it would keep track if all attachments of shared memory call `close()` at the end, which they should, and issue a warning if they do not. It would do this with the current code, no need to change anything. |
|
Date |
User |
Action |
Args |
2020-08-06 15:52:25 | damian.barabonkov | set | recipients:
+ damian.barabonkov, gvanrossum, pitrou, davin, pablogsal, vinay0410 |
2020-08-06 15:52:24 | damian.barabonkov | set | messageid: <1596729144.98.0.699407910065.issue38119@roundup.psfhosted.org> |
2020-08-06 15:52:24 | damian.barabonkov | link | issue38119 messages |
2020-08-06 15:52:24 | damian.barabonkov | create | |
|