Skip to content

sync: fix spin lock, add destroy() and try_lock()#24798

Merged
spytheman merged 10 commits into
vlang:masterfrom
kbkpbot:fix-sync-spin-lock-expected
Jun 27, 2025
Merged

sync: fix spin lock, add destroy() and try_lock()#24798
spytheman merged 10 commits into
vlang:masterfrom
kbkpbot:fix-sync-spin-lock-expected

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Jun 27, 2025

Copy link
Copy Markdown
Contributor
  1. Bug fix for spin lock expected value reset to unlock before retry.
  2. Update test.
  3. Add destroy().
  4. Add try_lock().
  5. Add valgrind ANNOTATE support to avoid false error report with spin lock detection. When using with valgrind, please add -d valgrind to enable this.

Original code(expected = C.atomic_load_byte(&s.locked)) will cause the updated test fail sometimes.

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23212

@kbkpbot kbkpbot changed the title sync: fix spin lock expected value = 0 sync: fix spin lock, add destroy() and try_lock() Jun 27, 2025
Comment thread vlib/sync/sync.c.v Outdated
Comment thread vlib/sync/sync.c.v
Comment thread vlib/sync/spinlock_test.v
Comment on lines +23 to +24
randval := rand.intn(100) or { 1 }
time.sleep(randval * time.nanosecond)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik the granularity of sleep is ~1-2ms on windows

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit d1d43ab into vlang:master Jun 27, 2025
75 checks passed
@kbkpbot kbkpbot deleted the fix-sync-spin-lock-expected branch June 27, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants