On Sep 21, 4:38 pm, Roger Gilliar <ro...@gilliar.de> wrote:
> I still have some problems to correctly understand the dosync  
> semantic.  What happens exaclty if two threads try to modify the same  
> list:

Nitpick: you're not modifying any lists. :) The only mutating things
are the Refs

>
> Example
>
> thread 1:
>
> (dosync
> append an item to a list
> .......
> )
>
> thread 2:
>
> (dosync
> remove an item from a list
> ..........
> )
>
> Is it true that If thread 1 is executed 'before' thread 2 all changes  
> in thread 2 are rollbacked and the dosync in thread 2  is executed  
> until the change can be succesfuly applied (in this example after the  
> dosync of thread 1 is finished )?

In a way, yes. If there are two threads that concurrently try to
change the same ref, then one of them gets retried. As far as I know,
it's not strictly defined which one "wins" in case of contention...
That depends on the kind of operation you do in your transaction
(commute, for example, may allow "conflicting" writes without causing
a retry)

In any case, the synchronisation guarantees that if you have a
starting list A, either the remove or the append operation will be
applied to it, producing A', and the remaining operation will be
applied to A', producing the final value of the Ref.

Oh, and rather than changing the discussion subject, please make a new
topic. Changing the subject makes searches more difficult.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to