Class: RaceGuard::SharedState::ConflictTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/race_guard/shared_state/conflict_tracker.rb

Overview

Tracks variable keys and threads for Epic 6.2 (concurrent writes, read/write overlap).

Pass mutex_protected: from the caller (Watcher) using the stack at the access site.

Constant Summary collapse

DETECTOR =
'shared_state:conflict'

Instance Method Summary collapse

Constructor Details

#initializeConflictTracker

Returns a new instance of ConflictTracker.



13
14
15
16
17
18
19
# File 'lib/race_guard/shared_state/conflict_tracker.rb', line 13

def initialize
  @mutex = Mutex.new
  @unprotected_writers = {} # key => Set<Thread>
  @last_unprotected = {} # key => { thread: Thread, kind: Symbol }
  @reported_concurrent_write = Set.new
  @reported_rw = Set.new
end

Instance Method Details

#process!(event, mutex_protected:) ⇒ Object



30
31
32
33
34
# File 'lib/race_guard/shared_state/conflict_tracker.rb', line 30

def process!(event, mutex_protected:)
  return unless event.is_a?(AccessEvent)

  @mutex.synchronize { process_unlocked!(event, mutex_protected: mutex_protected) }
end

#reset!Object



21
22
23
24
25
26
27
28
# File 'lib/race_guard/shared_state/conflict_tracker.rb', line 21

def reset!
  @mutex.synchronize do
    @unprotected_writers.clear
    @last_unprotected.clear
    @reported_concurrent_write.clear
    @reported_rw.clear
  end
end