@@ -847,6 +847,7 @@ impl VClockAlloc {
847847 kind : MemoryKind ,
848848 current_span : Span ,
849849 ) -> VClockAlloc {
850+ // Determine the thread that did the allocation, and when it did it.
850851 let ( alloc_timestamp, alloc_index) = match kind {
851852 // User allocated and stack memory should track allocation.
852853 MemoryKind :: Machine (
@@ -864,15 +865,16 @@ impl VClockAlloc {
864865 ( alloc_timestamp, alloc_index)
865866 }
866867 // Other global memory should trace races but be allocated at the 0 timestamp
867- // (conceptually they are allocated before everything).
868+ // (conceptually they are allocated on the main thread before everything).
868869 MemoryKind :: Machine (
869870 MiriMemoryKind :: Global
870871 | MiriMemoryKind :: Machine
871872 | MiriMemoryKind :: Runtime
872873 | MiriMemoryKind :: ExternStatic
873874 | MiriMemoryKind :: Tls ,
874875 )
875- | MemoryKind :: CallerLocation => ( VTimestamp :: ZERO , VectorIdx :: MAX_INDEX ) ,
876+ | MemoryKind :: CallerLocation =>
877+ ( VTimestamp :: ZERO , global. thread_index ( ThreadId :: MAIN_THREAD ) ) ,
876878 } ;
877879 VClockAlloc {
878880 alloc_ranges : RefCell :: new ( RangeMap :: new (
@@ -1454,7 +1456,7 @@ impl GlobalState {
14541456 // Setup the main-thread since it is not explicitly created:
14551457 // uses vector index and thread-id 0.
14561458 let index = global_state. vector_clocks . get_mut ( ) . push ( ThreadClockSet :: default ( ) ) ;
1457- global_state. vector_info . get_mut ( ) . push ( ThreadId :: new ( 0 ) ) ;
1459+ global_state. vector_info . get_mut ( ) . push ( ThreadId :: MAIN_THREAD ) ;
14581460 global_state
14591461 . thread_info
14601462 . get_mut ( )
@@ -1725,13 +1727,15 @@ impl GlobalState {
17251727 Ref :: map ( clocks, |c| & c. clock )
17261728 }
17271729
1730+ fn thread_index ( & self , thread : ThreadId ) -> VectorIdx {
1731+ self . thread_info . borrow ( ) [ thread] . vector_index . expect ( "thread has no assigned vector" )
1732+ }
1733+
17281734 /// Load the vector index used by the given thread as well as the set of vector clocks
17291735 /// used by the thread.
17301736 #[ inline]
17311737 fn thread_state_mut ( & self , thread : ThreadId ) -> ( VectorIdx , RefMut < ' _ , ThreadClockSet > ) {
1732- let index = self . thread_info . borrow ( ) [ thread]
1733- . vector_index
1734- . expect ( "Loading thread state for thread with no assigned vector" ) ;
1738+ let index = self . thread_index ( thread) ;
17351739 let ref_vector = self . vector_clocks . borrow_mut ( ) ;
17361740 let clocks = RefMut :: map ( ref_vector, |vec| & mut vec[ index] ) ;
17371741 ( index, clocks)
@@ -1741,9 +1745,7 @@ impl GlobalState {
17411745 /// used by the thread.
17421746 #[ inline]
17431747 fn thread_state ( & self , thread : ThreadId ) -> ( VectorIdx , Ref < ' _ , ThreadClockSet > ) {
1744- let index = self . thread_info . borrow ( ) [ thread]
1745- . vector_index
1746- . expect ( "Loading thread state for thread with no assigned vector" ) ;
1748+ let index = self . thread_index ( thread) ;
17471749 let ref_vector = self . vector_clocks . borrow ( ) ;
17481750 let clocks = Ref :: map ( ref_vector, |vec| & vec[ index] ) ;
17491751 ( index, clocks)
@@ -1774,9 +1776,7 @@ impl GlobalState {
17741776 #[ inline]
17751777 fn current_index ( & self , thread_mgr : & ThreadManager < ' _ , ' _ > ) -> VectorIdx {
17761778 let active_thread_id = thread_mgr. get_active_thread_id ( ) ;
1777- self . thread_info . borrow ( ) [ active_thread_id]
1778- . vector_index
1779- . expect ( "active thread has no assigned vector" )
1779+ self . thread_index ( active_thread_id)
17801780 }
17811781
17821782 // SC ATOMIC STORE rule in the paper.
0 commit comments