freenode/#clasp - IRC Chatlog
Search
23:08:07
drmeister
Yeah - that assignment involves this call: call std::__atomic_base<unsigned long>::operator=(unsigned long)
23:12:58
drmeister
Ok, does that help me though? Should I make them atomic and then use memory_ordered_relaxed everywhere that I don't care about memory order?
23:14:17
drmeister
I don't have a way to deal with atomic values in Common Lisp yet. I haven't made the conceptual leap.
23:14:41
drmeister
stassats: Do you have a few minutes - I can explain where this all came from - it's a good story.
23:15:44
drmeister
I figured out why my compile-file-parallel was only giving me about 1.5x speedup - it's the read lock in FIND-CLASS that is causing lock contention.
23:16:37
drmeister
So I've been trying to figure out how to fix all of the calls to (typep x '<cleavir-class>) that are invoking find-class and that are leading to lock contention.
23:17:04
drmeister
I started by replacing (typep x '<cleavir-class>) with predicates (<cleavir-class>-p x) - but that grew tiresome.
23:19:26
drmeister
I could - yes - for these cases. I thought instead though that I would put each class in a cons cell - and then use (classp x (car (load-time-value (ext:find-class-cell '<cleavir-class>))))
23:21:10
drmeister
In case some thread updates the class and code somewhere holds the cell for that class...
23:21:59
drmeister
I understand that these are cleavir classes and we aren't going to be modifying them - but still...
23:22:52
stassats
but even if it's atomic, what if you get the wrong value after you return from CAR?
23:23:50
stassats
suppose you have (when (typep x 'class) do-things-to-x) and something is redefined it at (when (typep x 'class) [here] do-things-to-x)
23:24:08
stassats
your atomicity won't help, it's the job of whoever does concurrent class changes to make things thread-safe
23:28:17
drmeister
Do you think it's a reasonable idea to store the class in the class table in the car of a cons cell and to let that cons cell out into Common Lisp land?
23:30:04
drmeister
Why not use a cons cell? I've been using them for cells in a couple of other places.
23:33:25
drmeister
Hmm, that seems a bit overkillish. Why would you do that? I'm asking because your rational may influence other things I'm thinking about.
23:33:43
stassats
modifying a class is not going to become atomic by declared a wrapper structure atomic, so you'll have a lock of some sort
23:34:46
stassats
why do that? that's how you program things, by creating structure out of amorphousness
23:38:42
drmeister
Then (load-time-value (find-class-holder '<cleavir-class>)) will return one of those.
23:39:07
drmeister
I'll still need a lock of some sort to read it - correct? That's what you were talking about
23:39:40
drmeister
(with-class-holder-lock-get-class (load-time-value (find-class-holder '<cleavir-class>)))
23:41:15
drmeister
So a function would work? (get-the-class-and-dont-give-a-crap-if-anyone-writes-to-the-class-holder (load-time-value (find-class-holder '<cleavir-class>)))
23:42:05
drmeister
And then (setf (find-class 'foo) new-class) uses serializes writes to the class-table with a lock?
23:43:42
drmeister
This seems dangerous - I was investigating the Read-Copy-Update approach for the class-table. https://en.wikipedia.org/wiki/Read-copy-update
23:44:54
drmeister
I was reading that wiki page and I was watching a couple of lectures on designing operating systems where they described Read-Copy-Update.
23:46:12
drmeister
I don't know, I thought if I don't declare things std::atomic that BAD THINGS would happen.
23:47:12
stassats
the problem with reordering is say you're changing a class from 3 slots to 5 slots, you're writing 3 to NSLOTS, then another code is iterating over all slots, it sees NSLOTS as being 5, but the slot vector isn't visible yet, and it's still holding 3 slots => error
23:47:36
drmeister
Seriously though - I thought worried about subtle race conditions that would be very difficult to debug if I don't use std::atomic.
23:49:59
drmeister
I probably can't plaster over the code with a consistent memory model at this point.
23:52:38
drmeister
I really appreciate the help here. So I'll create a ClassHolder_O class and have it store a class - I'll put those into the class-table. I'll read them without a lock (I'm nervous about this) but write to them with a lock.
23:56:12
drmeister
I don't have fences. I have pthreads mutexes and I have std::atomic and copy-and-swap.
23:58:30
stassats
i can't say that it'd be the right decision not now, but now, that's what i would've done
0:00:13
stassats
the only possible issue with this - the class itself is not decent yet, but the value will always be right
0:01:34
stassats
and you're attaching it to the symbol as well, if that works, then the wrapper cell would automagically work
0:05:27
drmeister
That just seemed way too simple. I could write the class into a slot in the symbol - that would be wasteful I guess because most symbols would not have a class.
0:05:47
drmeister
I could write it into the property list of the symbol - but people could screw with that.
0:07:29
drmeister
I'm starting to lose my train of thought. I am going to break for a bit and think about it.
0:24:18
drmeister
Hmmm, of course none of this class-holder stuff is portable - so we can't use it in the cleavir code. I'll have to talk with Bike about this.
0:28:26
drmeister
I figured out how to read the macOS Activity Monitor <sample process> output. It's really useful for figuring out what is going on.
0:33:16
stassats
if it doesn't exist you can actually stuff a function to run there, which then changes itself to run something else after it's determined what exists