SShortSingh.
Back to feed

Concurrency Bugs Explained: Why Shared State Needs Synchronization

0
·26 views

Concurrency within a single process involves multiple execution units, such as threads or goroutines, running simultaneously and potentially accessing the same data. A classic example shows how two threads each incrementing a shared counter can produce an incorrect result of 1 instead of 2, because both threads read the same stale value before either writes back. This race condition arises from the three-step nature of a simple increment operation — read, compute, and write — which can interleave unpredictably. Languages like Java, Go, and Python address this through synchronization primitives such as locks and mutexes, which enforce exclusive access to shared state during critical operations. An alternative approach, message passing, avoids shared state altogether by having execution units coordinate through exchanged messages rather than direct memory access.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Browser-based GIF compression and resizing without uploading files to a server

Chat apps still enforce upload limits on GIFs, and sending clips to online compressors raises privacy concerns. The approach described decodes and re-encodes GIFs entirely inside a browser tab, using a Web Worker to keep the main thread responsive. Memory is managed with a total pixel cap and downscaling for oversized files, while frame delays are clamped to 20 ms to avoid clients playing them slower. Opaque animations are further shrunk by writing only changed pixel regions between frames. To hit byte targets, the tool steps through a fixed sequence of color, scale, and frame reductions until the output fits.

0
ProgrammingDEV Community ·

How an iPhone Microphone Is Turned Into a Decibel Meter

A developer at W Lab describes building Noise Meter, an iPhone app that displays sound levels in decibels and logs them overnight. The core challenge is disabling iOS's default microphone processing, such as gain control and noise suppression, which would distort readings. The app applies standard frequency weightings (A, C, and Z) using filters derived from IEC 61672-1, adapted to the device's sample rate. Measurements are averaged into per-second records that track both energy-based equivalent levels and short-term peaks. The post also explains that dBFS readings must be converted to dB SPL to match standard sound level meter output.

0
ProgrammingDEV Community ·

Contao Edit-Multiple Flaw Let Restricted Users Modify Folders Outside Their Filemount

A vulnerability tracked as CVE-2026-126662 in the Contao content management system allows backend users restricted to one filemount to change folders outside that boundary via the Edit-Multiple bulk action. The flaw is an access-control bypass and requires an existing backend account with file-manager permissions. Contao lists affected versions as 4.0.0 before 5.3.54, 5.4.0 before 5.7.17, and 6.0.0 before 6.0.6, with fixes available in the corresponding patched releases. The advisory does not establish that outside files are executable, that anonymous visitors can exploit it, or that exploitation has occurred. Administrators are advised to update, verify restricted-user behavior, review file-change logs, and compare affected folders against trusted backups if the boundary may have been crossed.

0
ProgrammingDEV Community ·

Saudi refinery designs sovereign AI to turn engineers' operating knowledge into shared plant insight

A proposed sovereign AI architecture would let a Saudi refining operator run open-weight models on its own in-country hardware, reading only its internal systems of record. The system would link data from the historian, shift logs, work orders, change records, incident reports and turnaround findings into one governed model of the plant. Named agents would draft trip analyses, shift handovers and turnaround finding dispositions, which shift engineers would confirm or approve. Confirmed causes and decisions would be retained to improve later analyses, and a command centre would let engineers query the system with cited answers. The design responds to retirements of senior engineers and the heavy workload of plant turnarounds.