No, that isn't possible.
http://clojure.org/refs

Inside a transaction (a dosync call), values updated in another transaction
wont be seen. This means that the first transaction wont see the change
until it commits, at that moment it realizes that the ref that were altered
was changed outside of that particular transaction, and retries. All of this
happens automatically, so you wont have to worry.

On Tue, Apr 26, 2011 at 10:33 PM, Zlatko Josic <zlatko.jo...@gmail.com>wrote:

> Is this scenario posible :
>
> (def test-map (ref {}))
>
> (def test-map2 (ref {}))
>
> (defn process
> [map1 map2]
> (cond
>   (and (empty? @map1) (empty? @map2))
>   (dosync
>    ((alter map1 assoc key1 value1)
>     (alter map2 assoc key2 value2)
>     .....
>
>
> Suppose the process method is called from many threads. Is it posible that
> one thread tests first condition (empty? @map1) and gets true
> than another thread comits its transaction wich puts values in both maps.
> Now first thread check second
> condition (empty? @map2) which is false.
>
>
>
> On Tue, Apr 26, 2011 at 10:17 PM, Jonathan Fischer Friberg <
> odysso...@gmail.com> wrote:
>
>> The important part were that the "dosync" call is isolated. The condition
>> doesn't really matter.
>>
>> By the way: wouldn't it be simpler to create a new map instead of altering
>> unique-offers/all-offers?
>> (this is also more idiomatic)
>>
>>
>> On Tue, Apr 26, 2011 at 10:02 PM, Zlatko Josic <zlatko.jo...@gmail.com>wrote:
>>
>>> I have given only part of function. I have condition like this :
>>>
>>> (cond
>>>   (and (empty? @unique-offers) (empty? @all-offers))
>>>
>>> I change in dosync both unique-offers and all-offers. If I use your
>>> suggestion
>>>    (empty? @unique-offers) (dosync ... alter ...)
>>>
>>> Can I get in situation where unique-offers is old value but all-offers is
>>> new value?
>>>
>>> Thanks
>>>
>>>
>>>
>>> On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg <
>>> odysso...@gmail.com> wrote:
>>>
>>>> I don't know.
>>>> However, given the situation I think
>>>>
>>>> (cond
>>>>   (empty? @unique-offers) (dosync ... alter ...)
>>>>   :else (logger/log "error"))
>>>>
>>>> is better, since the change is more isolated.
>>>>
>>>> On Tue, Apr 26, 2011 at 9:45 PM, Zlatko Josic 
>>>> <zlatko.jo...@gmail.com>wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I use cond in dosync but it doesn't work. Here is a function code:
>>>>>
>>>>>
>>>>> (defn process-request
>>>>>   [offer args]
>>>>>   (logger/log "process called")
>>>>>   (let [offer-value (Double/parseDouble (:offer offer))
>>>>>           out-queue (:out-queue args)
>>>>>           unique-offers (:unique-offers args)
>>>>>           all-offers (:all-offers args)
>>>>>            streams (:streams offer)]
>>>>>       (dosync
>>>>>         (cond
>>>>>           (empty? @unique-offers)
>>>>>           ((logger/log "map" @unique-offers)
>>>>>             (alter unique-offers assoc offer-value streams))
>>>>>           :else (logger/log  "error")))))
>>>>>
>>>>> unique-offer is ref for map which is empty so condition (empty?
>>>>> @unique-offers) is true.
>>>>> Statement (alter unique-offers assoc offer-value streams) never changes
>>>>> unique-offers map.
>>>>> If I remove cond from function it works fine (The function has only
>>>>> dosyn and alter).
>>>>>
>>>>> What am I doing wrong?
>>>>>
>>>>> Thanks
>>>>>
>>>>> --
>>>>> 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
>>>>
>>>>
>>>>  --
>>>> 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
>>>
>>>
>>>  --
>>> 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
>>>
>>
>>  --
>> 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
>>
>
>  --
> 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
>

-- 
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