@@ -406,21 +406,17 @@ typedef struct {
406406} StgInfo ;
407407
408408/*
409- In free-threading, concurrent mutations to StgInfo is not thread safe.
410- Therefore to make it thread safe, when modifying StgInfo, `STGINFO_LOCK` and
411- `STGINFO_UNLOCK` macros are used to acquire critical section of the StgInfo.
412- The critical section is write only and is acquired when modifying the
413- StgInfo fields and while setting the `dict_final` bit. Once the `dict_final`
414- is set, StgInfo is treated as read only and no further modifications are
415- allowed. This allows to avoid acquiring the critical section for most
416- read operations when `dict_final` is set (general case).
417-
418- It is important to set all the fields before setting the `dict_final` bit
419- in functions like `PyCStructUnionType_update_stginfo` because the store of
420- `dict_final` uses sequential consistency memory ordering. This ensures that
421- all the other fields are visible to other threads before the `dict_final` bit
422- is set thus allowing for lock free reads when `dict_final` is set.
423-
409+ To ensure thread safety in the free threading build, the `STGINFO_LOCK` and
410+ `STGINFO_UNLOCK` macros use critical sections to protect against concurrent
411+ modifications to `StgInfo` and assignment of the `dict_final` field. Once
412+ `dict_final` is set, `StgInfo` is treated as read-only, and no further
413+ modifications are allowed. This approach allows most read operations to
414+ proceed without acquiring the critical section lock.
415+
416+ The `dict_final` field is written only after all other modifications to
417+ `StgInfo` are complete. The reads and writes of `dict_final` use the
418+ sequentially consistent memory ordering to ensure that all other fields are
419+ visible to other threads before the `dict_final` bit is set.
424420*/
425421
426422#define STGINFO_LOCK (stginfo ) Py_BEGIN_CRITICAL_SECTION_MUT(&(stginfo)->mutex)
0 commit comments