You might want to consider switching to agents (or something else) I don't
think it's possible to do what you want with refs.

Timothy Baldridge


On Wed, Jul 31, 2013 at 10:08 AM, Mike Drogalis <madrush...@gmail.com>wrote:

> Thanks for the link. :) I understand that the behavior I'm seeing is
> correct. Any idea how to achieve the desired behavior, though?
>
>
> On Wed, Jul 31, 2013 at 12:06 PM, Timothy Baldridge 
> <tbaldri...@gmail.com>wrote:
>
>> The answer is here:
>>
>>
>> https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LockingTransaction.java#L361
>>
>> Agents and watches are dispatched outside of the transaction locking.
>> This means that multiple transactions could be executing watches in
>> parallel, and hence execute out of order.
>>
>> Timothy Baldridge
>>
>>
>> On Wed, Jul 31, 2013 at 9:43 AM, Michael Drogalis 
>> <madrush...@gmail.com>wrote:
>>
>>> I can precisely exemplify the behavior here:
>>>
>>> https://gist.github.com/MichaelDrogalis/6123177
>>>
>>>
>>> On Wednesday, July 31, 2013 11:13:17 AM UTC-4, Michael Drogalis wrote:
>>>>
>>>> Aaron: Yep, I'm aware - and am using the value provided by the last
>>>> parameter.
>>>>
>>>> This is going to be tough to show the problem without bringing more
>>>> details of my concurrency set up.
>>>> I'm not sure if this will exhibit the problem, but this is what it
>>>> boils down to:
>>>>
>>>> https://gist.github.com/**MichaelDrogalis/6122834<https://gist.github.com/MichaelDrogalis/6122834>
>>>>
>>>> When enough threads are trying to write to the queue, the watches
>>>> triggered later can finish before watches triggered earlier.
>>>>
>>>>
>>>> On Wednesday, July 31, 2013 11:05:16 AM UTC-4, Aaron Cohen wrote:
>>>>>
>>>>> A watcher fn has 4 parameters: key, reference, old-state, new-state
>>>>>
>>>>> If you use old-state and new-state rather than the reference, you
>>>>> should not see your problem.
>>>>>
>>>>> --Aaron
>>>>>
>>>>>
>>>>> On Wed, Jul 31, 2013 at 11:00 AM, Michael Drogalis <madru...@gmail.com
>>>>> > wrote:
>>>>>
>>>>>> Problem:
>>>>>>
>>>>>> I have a ref representing a queue of people in line.
>>>>>> I add a watch to the ref to print out the contents of the queue
>>>>>> whenever it changes.
>>>>>> Naturally, and expected, the following can happen if queuing happens
>>>>>> in rapid succession:
>>>>>>
>>>>>> Queue: []
>>>>>> <add "Mike" to queue>
>>>>>> <add "John" to queue>
>>>>>>
>>>>>> console: "Queue is Mike, John"
>>>>>> console: "Queue is Mike"
>>>>>>
>>>>>> I'd like to write a UI for this program, but I clearly can't reliably
>>>>>> render based on the result delivered
>>>>>> by the add-watch hook. What's the solution for this problem?
>>>>>>
>>>>>> --
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Clojure" group.
>>>>>> To post to this group, send email to clo...@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+u...@googlegroups.com
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en>
>>>>>> ---
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Clojure" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to clojure+u...@googlegroups.com.
>>>>>> For more options, visit 
>>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>>> .
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>  --
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+unsubscr...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> “One of the main causes of the fall of the Roman Empire was that–lacking
>> zero–they had no way to indicate successful termination of their C
>> programs.”
>> (Robert Firth)
>>
>> --
>> --
>> 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 a topic in the
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/clojure/0b5HWJE6Jx4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> clojure+unsubscr...@googlegroups.com.
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to