浏览代码

Fix potential bad optimization bug in sync.Ticket_Mutex

When locking, we were not loading m.serving atomically and so the optimizer
could have hoisted the check out of the loop, thus resulting in an infinite loop.
Tetralux 5 年之前
父节点
当前提交
3afa2736b7
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      core/sync/sync.odin

+ 1 - 1
core/sync/sync.odin

@@ -17,7 +17,7 @@ ticket_mutex_init :: proc(m: ^Ticket_Mutex) {
 
 ticket_mutex_lock :: inline proc(m: ^Ticket_Mutex) {
 	ticket := atomic_add(&m.ticket, 1, .Relaxed);
-	for ticket != m.serving {
+	for ticket != atomic_load(&m.serving, .Acquire) {
 		yield_processor();
 	}
 }