Do you mean this? (I have never understood atomic compare and exchange, myself; the description of it - "evaluates the value of Item; compares the value of Item with the value of Prior; if equal, assigns Item the value of Desired; otherwise, makes no change to the value of Item" - definitely seems like it would just be a no-op, every time, but maybe there's something I'm missing. I mean, your essentially doingOctocontrabass wrote:Write an address to the goto_address member and the AP will begin executing at that address. The AP will set its stack pointer to target_stack when it begins executing.
You have to perform the write to goto_address in a manner that guarantees memory consistency. For example, in C, you would use atomic_store_explicit with memory_order_release. I'm sure Ada has an equivalent, but I don't know what it would be.
Code: Select all
if item = prior then
item := desired;
end if;
Uhm. Wow. I don't know if I should be amazed or horrified that it lets you just casually do that as though it weren't something possibly dangerous. Frankly I'm amazed that the runtime didn't go "Hey WTF" or something. And I'm unsure why the "Programming in Ada 2012" book doesn't mention being able to do that; it explicitly states that Ada does not allow for pointer arithmetic, but maybe Barnes was explicitly talking about "safe" Ada.iansjack wrote:Pointer arithmetic is supported in Ada via the System.Storage_Elements package. Here's a completely useless example that demonstrates pointer arithmetic (and how unsafe it is as it allows access beyond the bounds of the array!):with outputCode: Select all
with System; with System.Storage_Elements; use System.Storage_Elements; with Ada.Text_IO; use Ada.Text_IO; procedure Main is type IntegerAccess is access Integer; type IntegerArray is array (1 .. 4) of Integer; arr : IntegerArray := (1, 2, 3, 4); i : System.Address; begin i := arr'Address; for j in 1 .. 5 loop declare int : Integer; for int'Address use i; begin Put_Line (int'Image); end; i := i + Integer'Size /8; end loop; end Main;
Code: Select all
1 2 3 4 0