Well, I even don't know how to expand the condition creation. Is
anyone can help me providing example for this?
Calling my-macro like this would bind some values to a b and c (number
of arguments is vary) so when in use
(my-macro [ a b c]
(println a) (println b))
I would get
> "hello"
> "wo
(ns michael.ds.monitor
(:import [java.util.concurrent.locks ReentrantLock Condition ]))
(def locks (atom { :monitors {} :conds {} }))
(defn create-monitor[]
(ReentrantLock.))
(defn create-cond[m]
(.newCondition m))
(defmacro lock-monitor[ lck & body ]
`(let [z# ~
Yeah, but I'm missing conditions (with ability to spawn multiple instances)
and the use wait and signal.
It would be nice to have:
(some where in code
(locking [my-lock c1 c2]
(wait c1)
bla bla bla. ...
(signal c2)))
(in other place
(locking [my-lock c1 c2]
(signal c1)
...
@Michael,
There is already a monitor mechanism available in Clojure via the
'locking' macro or more primitive monitor-enter, monitor-exit. So in
your case all you have to implement is the blocking behavior, I'm not
sure if it can be already done somehow using just Clojure elements.
The above code
Hi,
On Fri, May 14, 2010 at 01:47:00PM -0700, ka wrote:
> Isn't ensure necessary? Because http://clojure.org/refs says that -
> "No changes will have been made by any other transactions to any Refs
> that have been ref-set/altered/ensured by this transaction." It
> doesn't guarantee that a ref
> You can get rid of the I/O in the transaction and still see a consistent
> snapshot by simply return the contents of the refs.
>
> (defn report-status
> []
> (apply println (dosync [...@my-hash @new-keys])))
>
> Sincerely
> Meikel
>
> --
Isn't ensure necessary? Because http://clojure.org/re
Thanks for help. I have just used synchronization mechanizm from Java.
Here is a code:
monitor.clj
(ns michael.ds.monitor
(:import [java.util.concurrent.locks ReentrantLock Condition ]))
(defn create-monitor[]
(ReentrantLock.))
(defn create-cond[m]
(.newCondition m
Hi,
On Fri, May 14, 2010 at 10:59:34AM -0700, ka wrote:
> (defn report-status []
> (dosync
> (ensure my-hash)
> (ensure new-keys)
> (println @my-hash)
> (println @new-keys)
> ))
You can get rid of the I/O in the transaction and still see a consistent
snapshot by simply ret
Few notes -
1. report status is not particularly good as it has io in a dosync.
2. Spelling of consume fn.
3. The consumers are not at all fair as they always take the first of
the set.
Please let me know if anyone sees some issues with the above code or
how to make it better.
On May 14, 10:59 pm
If add-watch is not what you want because you want the consumers to
have a life of their own, then does something like this work? -
(def my-hash (ref {}))
(def new-keys (ref #{}))
(defn produce []
(let [new-key (rand-int 10)
new-val "P"]
(Thread/sleep 100)
(dosync
(alter
there is a way to subscribe to reference types in clojure via
the add-watch function.
you can with wherry little hackering make a call me once function
that under the hod whill hock upp and remove the watcher when
called
this whill not be syncronus butt its easy to do
!!!EXAMPLE
(get-data-once M
Hi,
On 12 Mai, 15:37, Michael Jaaka wrote:
> I have atom, which is some structure (my hashmap).
>
> Now periodically some data are assoc to my hashmap with swap!
> (producer).
>
> Also there is a consumer of these added data, which takes the data (in
> fact it just re-organize my hashmap, to mar
Hi!
Let me tell you my problem:
I have atom, which is some structure (my hashmap).
Now periodically some data are assoc to my hashmap with swap!
(producer).
Also there is a consumer of these added data, which takes the data (in
fact it just re-organize my hashmap, to mark the fact that somethin
13 matches
Mail list logo