]> Savannah Git Hosting - gnulib.git/commitdiff
windows-once: Improve comments.
authorBruno Haible <bruno@clisp.org>
Sat, 1 Jun 2024 00:31:25 +0000 (02:31 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Jun 2024 23:16:46 +0000 (01:16 +0200)
* lib/windows-once.c (glwthread_once): Mention the 'started' field in
the comments.

ChangeLog
lib/windows-once.c

index 85fc1de073b54d0091a07dbf00513b0da3280327..8e09876ea0f198f52b59b256c4fc5bebf548dfe1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-31  Bruno Haible  <bruno@clisp.org>
+
+       windows-once: Improve comments.
+       * lib/windows-once.c (glwthread_once): Mention the 'started' field in
+       the comments.
+
 2024-05-30  Bruno Haible  <bruno@clisp.org>
 
        assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11.
index 4d234e0bf265cf22435f9935507265df59abbafd..a8b9e0f3ae0b3333299404bed7593b71ee447908 100644 (file)
@@ -58,9 +58,10 @@ glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void))
                 abort ();
             }
         }
-      /* Here once_control->inited > 0.  */
+      /* Here once_control->started == 0 and once_control->inited > 0.  */
       if (InterlockedDecrement (&once_control->num_threads) == 0)
-        /* once_control->num_threads is now zero, and once_control->inited > 0.
+        /* once_control->num_threads is now zero, and
+           once_control->started == 0 and once_control->inited > 0.
            No other thread will need to use the lock.
            We can therefore destroy the lock, to free resources.  */
         /* If once_control->inited is == 1, set it to 2.  */
@@ -73,15 +74,16 @@ glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void))
      * The first thread to go through the once_control->started fence
        initializes the lock and moves inited from <= 0 to > 0.  The other
        threads don't move inited from <= 0 to > 0.
+     * started, once == 0, stays == 0.
      * inited, once > 0, stays > 0 (since at the place where it is assigned 0,
        it cannot be > 0).
      * inited does not change any more once it is 2.
        Therefore, it can be changed from 1 to 2 only once.
      * DeleteCriticalSection gets invoked right after inited has been changed
        from 1 to 2.  Therefore, DeleteCriticalSection gets invoked only once.
-     * After a moment where num_threads was 0 and inited was > 0, no thread can
-       reach an InitializeCriticalSection or EnterCriticalSection invocation.
-       Proof:
+     * After a moment where num_threads was 0 and started was 0 and
+       inited was > 0, no thread can reach an InitializeCriticalSection or
+       EnterCriticalSection invocation.  Proof:
        - At such a moment, no thread is in the code range between
            InterlockedIncrement (&once_control->num_threads)
          and
@@ -96,7 +98,7 @@ glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void))
      * From this it follows that:
        - DeleteCriticalSection cannot be executed while the lock is taken
          (because DeleteCriticalSection is only executed after a moment where
-         num_threads was 0 and inited was > 0).
+         num_threads was 0 and started was 0 and inited was > 0).
        - Once DeleteCriticalSection has been executed, the lock is not used any
          more.
    */