clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
2021-03-23T18:54:25.013300Z

I had an idea for a deftype improvement (https://ask.clojure.org/index.php/10369/add-atomic-field-updaters-to-deftype) which may be of interest to people here, but also may be pretty niche (the small set of people who use deftype, who use volatile-mutable, who want atomic updates)

ghadi 2021-03-23T19:09:58.013900Z

@hiredman what about VarHandles?

ghadi 2021-03-23T19:17:43.014400Z

those sort of subsume AFUpdaters, adding capabilities

2021-03-23T19:24:07.016300Z

Yeah looks interesting I hadn't seen them before, the api there is certainly clunkier to use from clojure(all those java varargs)

ghadi 2021-03-23T19:24:54.016800Z

they are all signature polymorphic calls, which Clojure can't call fully

2021-03-23T19:27:24.020400Z

Seems like a huge hassle then, I just want to cas on type fields without having to do weird hacks to construct the updater once in a context that can access the field

ghadi 2021-03-23T19:30:19.021700Z

@hiredman why CAS on the type fields, rather than reference an atom?

ghadi 2021-03-23T19:30:44.022400Z

I could imagine it's memory overhead, just trying air assumptions

2021-03-23T19:31:08.022700Z

Exactly that

2021-03-23T19:31:28.023200Z

Building a new reference type

2021-03-23T19:32:08.023600Z

I want them to be as lean as possible

2021-03-23T19:32:47.024700Z

Memory overhead both just in terms of more objects but also in terms of pointer chasing

1
2021-03-23T20:46:42.025500Z

https://gist.github.com/6c111db73ac020e1a234e0361e2e067a is an example of the hack I have now (adding a 0-arg invoke method to build the updater and return it)

2021-03-23T20:50:27.026800Z

and I totally forgot about the double layers function call hacks because the repl really likes to invoke all functions using apply

ghadi 2021-03-23T20:56:39.028Z

I like that deftypes don't allow a set! to escape into a closure. Care has to be taken with both AFUs and VarHandles to not let them leak out

ghadi 2021-03-23T20:57:24.028700Z

closure, not clojure 😅

alexmiller 2021-03-23T21:11:33.028800Z

This question would be much rather if you wrote it as "I have problem X, one possible solution is Y" rather than "Add Y" (Ghadi's questions below signify perhaps several possible other solutions as well)

alexmiller 2021-03-23T21:12:48.029Z

The question does hint at all at why you want this or how it would be used with which we could compare possible solutions

2021-03-23T21:40:57.030500Z

AtomicReferenceFieldUpdater only lets you do safe operations(same operations as on an atom + lazySet + weakCompareAndSet) on the field

2021-03-23T21:44:52.030600Z

I thought that this: > I have been playing with implementing some alternative concurrency constructs in Clojure which ends up using a lot of atomic reference fields. It is easy enough to just wrap an atom around all these things, but that introduces an extra object and layer of indirection. was that

2021-03-23T21:46:39.030800Z

should it just not mention AtomicReferenceFieldUpdater at all and just say "the jvm lighter weight ways to do cas on fields, it be would be nice to expose"?