Since two threads cannot use the connection concurrently, it sounds like
you just need the locking macro:

    (locking conn
      (.write conn "blah")
      (.read conn))

- James


On 2 June 2014 22:15, Joachim De Beule <joachim.de.be...@gmail.com> wrote:

> Dear group,
>
> I have the following use case: I have a socket connection to an external
> service. I want several threads to use the same connection.
> Importantly,  in order to get a synchronized response from the external
> service, every write must be followed by a read before another write is
> performed.
>
> This seems a rather general problem, so I'm guessing there is a "standard"
> solution?
>
> One strategy is to implement a Connection record that implements an atomic
> write/read protocol function. This function, when called from a thread A
> during another, unfinished call from a different thread B, blocks thread A
> and queues it until thread B's write/read call is finished and the
> connection is released. Is this a good strategy? How would it best be
> implemented using clojure's concurrency supporting features?
>
> All advice much appreciated!
> Joachim
>
>
>  --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to