@@ -12,9 +12,11 @@ namespace Immutable.Audience
1212 // Entry point for the Immutable Audience SDK.
1313 public static class ImmutableAudience
1414 {
15- // Reference fields are written inside _initLock; readers fence off the volatile _initialized load.
16- // _state (consent + userId) is volatile for release/acquire visibility; writes
17- // are serialised under _initLock (Identify / Reset also take it to keep the pair atomic).
15+ // Reference fields are written inside _initLock; readers check the
16+ // `volatile _initialized` flag first so they never see a half-initialised state.
17+ // _state (consent + userId) is `volatile` so a write on one thread is
18+ // visible on any other. Writes happen under _initLock (Identify / Reset
19+ // also take it) so the two fields always move together.
1820 private static AudienceConfig ? _config ;
1921 private static DiskStore ? _store ;
2022 private static EventQueue ? _queue ;
@@ -200,7 +202,8 @@ public static void Identify(string userId, string identityType, Dictionary<strin
200202
201203 AudienceConfig ? config ;
202204 ConsentLevel level ;
203- // Update _state under _initLock so (consent, userId) stays a consistent pair.
205+ // Update consent + userId under the init lock so they always move
206+ // together — another thread reading _state never sees one half-updated.
204207 lock ( _initLock )
205208 {
206209 if ( ! _initialized ) return ;
@@ -592,8 +595,9 @@ private static bool CanTrack()
592595 private static Dictionary < string , object > ? SnapshotCallerDict ( Dictionary < string , object > ? src ) =>
593596 src != null ? new Dictionary < string , object > ( src ) : null ;
594597
595- // Re-reads _state under _drainLock to close the Track-races-SetConsent
596- // window: drops on downgrade to None, strips userId on downgrade to Anonymous.
598+ // Checks the current consent inside the drain lock. If consent has
599+ // since dropped to None the message is discarded. If it dropped to
600+ // Anonymous the userId is stripped.
597601 private static void EnqueueTrack ( Dictionary < string , object > ? msg )
598602 {
599603 _queue ? . EnqueueChecked ( msg , m =>
0 commit comments