> On 9/21/06, Mikhail Fursov <[EMAIL PROTECTED]> wrote:
>>
>> Weldon, Robin
>> thank you for the comments.
>> There are just a few steps left to do before Jitrino.OPT will have
>> usable
>> "unboxed" package implementation.
>>
>> Right now I'm working on atomic operations (prepare/attempt pair), and I
>> do
>> not completely understand the semantic of the 'prepare' method.
>> The "prepareXYZ" method looks like a simple load and is not an atomic
>> operation by itself. Are there any examples that describe these
>> operations
>> in details?
>
>
>
> Robin will correct me if I am wrong.
>
> I think the idea is that this is a generic API intended to be used for
> accessing "compare and swap" facilities on a bunch of different hardware.
> And the actual hardware has different memory models, different CAS
> semantics, etc.
>
> Basically the generic facility needed is to first read the CAS target
> memory
> location (this is the "prepare").  If the memory is sitting at a specific
> value (this is the "do something"), then do an "attempt" as follows:
>
> old_contents =  CAS(expected_specfic_value_that_I_just_read,
> some_new_value,
> target_memory_location)
>
> If the old_contents are identical to
> expected_specific_value_that_I_just_read, we know that the CAS succeeded.
> In other words, you won the competition.  Otherwise you lost.
>
> I imagine the following situation in user's code:
>>
>> prepareXYZ()
>> do something
>> attempt()
>>
>> Is this code correct?
>>

You're correct.

The prepare/attempt was designed to match architectures (PPC, Alpha ...)
with a load-locked/store-conditional instruction pair.

The standard code fragment for a synchronized update is

do {
  oldVal = x.prepare();
  newVal = f(oldVal);
} while (!x.attempt(oldVal,newVal));

As an aside, vmmagic should probably have CAS as a primitive rather than
prepare/attempt, but I don't think that's going to happen in the immediate
future.

cheers


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to