feat: migrate all write flag and cnt0 accesses to atomic macros#247
Open
oguyon wants to merge 2 commits intoframework-devfrom
Open
feat: migrate all write flag and cnt0 accesses to atomic macros#247oguyon wants to merge 2 commits intoframework-devfrom
oguyon wants to merge 2 commits intoframework-devfrom
Conversation
Replace all direct accesses to IMAGE_METADATA.write and cnt0++ across coremods, milk-extra-src, examples, and CLI with the new SHMIM_WRITE_ACQUIRE/RELEASE/LOAD and SHMIM_CNT0_INCREMENT macros from ImageStruct.h. This ensures proper memory fences for cross-process synchronization of shared memory streams, eliminating race conditions from stale reads and compiler reordering.
Point submodule to commit 5176658 which adds the SHMIM_WRITE_*/SHMIM_CNT0_* atomic accessor macros in ImageStruct.h. Required for the milk-side migration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate all direct
md->writeandmd[0].writeassignments, and all directmd->cnt0++increments across coremods, milk-extra-src plugins, examples, and CLI to use the newSHMIM_WRITE_*andSHMIM_CNT0_*atomic accessor macros fromImageStruct.h.This is the milk-side companion to the ImageStreamIO PR (milk-org/ImageStreamIO#69) that defines the macros. Together, they eliminate a class of cross-process race conditions from stale reads and compiler reordering of the write flag and frame counter.
Rationale
See milk-org/ImageStreamIO#69 for the full rationale on why atomic accessors are needed for
IMAGE_METADATA.writeandcnt0. This PR performs the mechanical migration of ~95 call sites across 34 files in the milk repository to use the new macros.What changed
Every instance of:
was replaced with:
Diagnostic reads (e.g.,
image_stats.c,imagemon.c) now useSHMIM_WRITE_LOAD()andSHMIM_CNT0_LOAD()for acquire-ordered reads.Backward compatibility
This is a code-only change — no struct layout, ABI, or shared memory format changes. All modifications are source-level substitutions of direct field access with macro calls that operate on the same underlying fields at the same offsets. The compiled binaries produce identical SHM layouts and are fully interoperable with older processes.
Opt-in write blocking
The write flag remains an opt-in cooperative mutex. Readers that want to block until a write completes call
ImageStreamIO_BusywaitForNoWrite(), which now uses atomic loads internally. All writer code paths now useSHMIM_WRITE_ACQUIRE/RELEASEconsistently, ensuring that any reader opting into write blocking will see a fully consistent frame.Readers that do not call
BusywaitForNoWriteare unaffected — they continue to read immediately after semaphore wakeup, as before.Files changed (34 files, +140 −140)
coremods:
COREMOD_memory/: image_copy, image_copy_shm, stream_diff, stream_halfimdiff, stream_merge, stream_paste, stream_pixmapdecode, stream_updateloop, stream_TCP/UDP_receive, im3D_to_stream2D, image_mk_fromCOREMOD_arith/imfunctions.cmilk-extra-src plugins:
linalgebra/: GPU_loop_MultMat_execute, MVMextractModes, cublas_Coeff2Map_LooplinARfilterPred/: applyPF, build_linPF, linARfilterPredimage_basic/streamfeed.cimage_format/: extract_utr, stream_temporal_statsimg_reduce/img_reduce.cinfo/: image_stats, imagemon, stream_monprocexamples:
module templates:
AI Authorship
Prompt Summary
Codebase-wide migration of all direct
IMAGE_METADATA.writeandcnt0field accesses to use the new atomic accessor macros, as part of the cross-process race condition remediation effort.