Multiple threads can access the elements of
System.Tasking.Debug.Known_Tasks concurrently. While the compiler will
generally produce code that reads and writes Task_Ids atomically since
Task_Id is word size, it is best to be explicit to prevent data race
issues that may arise from non-atomic component accesses.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * libgnarl/s-tasdeb.ads (Known_Tasks): Add Atomic_Components
        aspect.
diff --git a/gcc/ada/libgnarl/s-tasdeb.ads b/gcc/ada/libgnarl/s-tasdeb.ads
--- a/gcc/ada/libgnarl/s-tasdeb.ads
+++ b/gcc/ada/libgnarl/s-tasdeb.ads
@@ -65,9 +65,11 @@ package System.Tasking.Debug is
    -- General GDB support --
    -------------------------
 
-   Known_Tasks : array (0 .. 999) of Task_Id := (others => null);
+   Known_Tasks : array (0 .. 999) of Task_Id := (others => null)
+     with Atomic_Components;
    --  Global array of tasks read by gdb, and updated by Create_Task and
-   --  Finalize_TCB
+   --  Finalize_TCB. Ensure access to its components is atomic to allow
+   --  lock-free concurrent access.
 
    Debug_Event_Activating           : constant := 1;
    Debug_Event_Run                  : constant := 2;


Reply via email to