You could do this with core.async. Make a channel that takes messages, and
then run a go loop that pulls messages off the message channel and prints
them. Then only one part of the program is ever printing. Any other part
that wants to print a message can push onto the channel.




On Fri, Apr 11, 2014 at 8:35 AM, Cecil Westerhof <cldwester...@gmail.com>wrote:

> I have the following functions in my concurrent program:
> (def time-format (new java.text.SimpleDateFormat "HH:mm:ss"))
>
> (defn now []
>   (new java.util.GregorianCalendar))
>
> (defn give-message [message]
>   (println (format "%s: %s" (. time-format format (. (now) getTime))
> message)))
>
>
> But sometimes a new message from a different thread is displayed, before
> the current message is ready:
> 10:34:57: Different for      4194573 (9.313226e-10, 2.220304e-16)10:34:57:
> Different for      4198042 (9.313226e-10, 2.218469e-16)
>
> 10:34:57: Different for      8389473 (1.862645e-09, 2.220217e-16)
>
>
> Is there a way to make give-message atomic, so it would be displayed as:
> 10:34:57: Different for      4194573 (9.313226e-10, 2.220304e-16)
> 10:34:57: Different for      4198042 (9.313226e-10, 2.218469e-16)
> 10:34:57: Different for      8389473 (1.862645e-09, 2.220217e-16)
>
>
> I attached the complete program. Any hints to implement it better are
> appreciated.
>
> --
> Cecil Westerhof
>
> --
> 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