Advertisement
SimonWright

Atomic_Operations

Nov 28th, 2020
4,650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 0.62 KB | None | 0 0
  1. with Ada.Text_IO; use Ada.Text_IO;
  2. with System.Atomic_Operations.Modular_Arithmetic;
  3. procedure Main is
  4.  
  5.    type Unsigned_Atomic is mod 2 ** 32 with Atomic;
  6.  
  7.    package Atomic_Operations
  8.    is new System.Atomic_Operations.Modular_Arithmetic
  9.      (Atomic_Type => Unsigned_Atomic);
  10.  
  11.    X : aliased Unsigned_Atomic := 0;
  12.  
  13.    Loops : constant := 1_000_000;
  14.  
  15.    task type T;
  16.    task body T is
  17.    begin
  18.       for J in 1 .. Loops loop
  19.          Atomic_Operations.Atomic_Add (X, 1);
  20.       end loop;
  21.    end T;
  22.  
  23. begin
  24.  
  25.    declare
  26.       A, B : T;
  27.    begin
  28.       null;
  29.    end;
  30.  
  31.    Put_Line (X'Image);
  32.  
  33. end Main;
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement