<discocaml>
<contificate> I think he's talking about doing a context switch
<discocaml>
<contificate> you could conceive of ways to do lightweight threads with `__morestack` in C, but a few parts of it would require assembly: pivoting the stack pointer, in particular
<discocaml>
<shawnfrostx> @cedb you can create a list of arguments using either the sequence or comma separated combinator like so (https://pastebin.com/E4dgux5P). If the args that you care about are separate arguments and not meant to be treated together, you can chain them as optional arguments I guess.
ced2 has joined #ocaml
<companion_cube>
My understanding is that you'd need to trigger a context switch in *another thread* (otherwise you can just do cooperative scheduling)
<companion_cube>
And that's not doable on Linux as far as I know
ced2 has quit [Ping timeout: 248 seconds]
<discocaml>
<contificate> well, in terms of raw threads, probably
<discocaml>
<contificate> but, to me, it all feels quite loose when you discuss GC'd runtime with effectively bake in cooperation
<discocaml>
<contificate> tick thread, domain state request interrupt, safe points, primitives explicitly releasing the domain lock, etc.
<discocaml>
<contificate> they are preempted but cooperate to be preemptible
<discocaml>
<contificate> with the runtime, that is
<discocaml>
<contificate> think there's even a comment in the domain state table saying you could change one of the minor heap values at runtime to ensure the next allocation fails, on purpose
<discocaml>
<contificate> even if it's not "preempt now!" as a kernel scheduler may be able to do well
<companion_cube>
If you modify the runtime maybe
<companion_cube>
If you use it as is I doubt you can do much
<discocaml>
<cod1r> i do i get as knowledgeable as contificate
<discocaml>
<cod1r> how do i get as knowledgeable as contificate
<discocaml>
<dubious245> Patience and practice or dark magic and cannibalism.
<discocaml>
<contificate> I know nothing about anything
<discocaml>
<dubious245> How much do you know about Ocaml?
<discocaml>
<contificate> very little
<discocaml>
<cod1r> bros being humble
<discocaml>
<cod1r> tsk tsk tsk
<discocaml>
<regularspatula> Anyone using menhir in vscode and getting unusual file formatting? I believe it’s ocamlformat’s doing but I’m not 100% sure
<discocaml>
<regularspatula> I don’t remember any issues in the past, but I was using emacs last time in was using menhir
<discocaml>
<dubious245> What is 'unusual' file formatting in this case?
<discocaml>
<regularspatula> Pretty much each token on its own line, separated by an additional new line
<discocaml>
<regularspatula> hmm don't think it's ocamlformat's fault actually...when I'm running `dune build --watch` and then run "format file" in vscode, then it does the weird formatting, but when `dune build --watch` is not running, the "format file" command does not try to format the mly file
hannes_ has joined #ocaml
hannes has quit [Ping timeout: 265 seconds]
wickedshell has quit [Ping timeout: 268 seconds]
<discocaml>
<dubious245> I've been corrupted. Cursed. I blame yall.
<discocaml>
<dubious245>
<discocaml>
<dubious245> Other programming languages aren't fun to program in anymore, I just tried doing something in C# and I wasn't satisfied.
<discocaml>
<Kali> haha, that's how it feels for me too
<discocaml>
<Kali> i don't even enjoy programming in lua much anymore which used to be my favorite language
Haudegen has quit [Quit: Bin weg.]
<discocaml>
<dubious245> You curse me and now you laugh at my pain. For shame.
grobe0ba has quit [Remote host closed the connection]
grobe0ba has joined #ocaml
wickedshell has joined #ocaml
wbooze has quit [Read error: Connection reset by peer]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 252 seconds]
haesbaert has joined #ocaml
chiselfuse has quit [Ping timeout: 264 seconds]
chiselfuse has joined #ocaml
Serpent7776 has joined #ocaml
hannes_ has quit [Quit: leaving]
bartholin has joined #ocaml
Serpent7776 has quit [Ping timeout: 276 seconds]
patrick_ is now known as patrick
patrick has quit [Changing host]
patrick_ has joined #ocaml
olle has joined #ocaml
Tuplanolla has joined #ocaml
YuGiOhJCJ has joined #ocaml
pi3ce has quit [Ping timeout: 245 seconds]
pi3ce has joined #ocaml
Haudegen has joined #ocaml
Exa has quit [Ping timeout: 252 seconds]
Exa has joined #ocaml
ski has quit [Ping timeout: 252 seconds]
ski has joined #ocaml
Serpent7776 has joined #ocaml
<discocaml>
<._null._> I've had this happen to me as well. I should investigate and report this
<discocaml>
<princemmv> I saw that OCaml was part of GSoC (and other open source mentorship programs) a few years or so back.
<discocaml>
<princemmv>
<discocaml>
<princemmv> Does that still exist in any form now?
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
<discocaml>
<princemmv> Oh seems like outreachy is the answer
<discocaml>
<princemmv> Oh seems like outreachy is the answer but it is for underrepresented groups only which I probably wouldn't qualify for.
<discocaml>
<princemmv>
<discocaml>
<princemmv> Any other similar programs?
olle has quit [Ping timeout: 276 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 260 seconds]
<discocaml>
<regularspatula> Yeah it’s pretty weird. To work around, I turned off format on save for menhir and ocamllex modes
divya has quit [Ping timeout: 252 seconds]
divya has joined #ocaml
<discocaml>
<froyo> > Dubious: Oh wow that looks awful.
<discocaml>
<froyo> it looks absolutely great with all its native gui goodness. probably weighs a few megabytes. 100% pure SOUL
bibi has joined #ocaml
<discocaml>
<dubious245> It's 0 megabytes because I cant get it to compile. :sylveon_sip:
<discocaml>
<dubious245> I made a switch for version 4.14, I installed all the dependencies, I am not sure why I cant get it to compile.
<discocaml>
<holmdunc> Fashions change. Having countless little icons on toolbars used to be a positive!
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
Exa has quit [Quit: see ya!]
Exa has joined #ocaml
<dh`>
woops, sorry I disappeared yesterday
<dh`>
you trigger a context switch with a timer interrupt
<dh`>
in userland that's basically just a SIGALRM handler
<dh`>
the SIGALRM handler then just calls your thread package's yield function or equivalent
<dh`>
no asm involvd
<dh`>
or involved
<discocaml>
<contificate> the tick thread would signal `SIGVTALRM` (named `SIGPREEMPTION`) in OCaml 4
<discocaml>
<contificate> not entirely sure how it actually works; my understanding is you can't just preempt at random points as it could be GC unsafe, so I don't know how the the timeslice is actually enforced; just so happens many runtime functions in OCaml will release the runtime lock anyway
<discocaml>
<contificate> understanding is OCaml 5 doesn't use signals for this purpose any more, the tick thread sets an atomic value in the domain state "request_external_interrupt" or whatever
<rustyne>
regularspatula: I don’t think formatting was added for mll/mly
<companion_cube>
dh`: how do you make sure that the correct thread catches the signal?
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 276 seconds]
<dh`>
signals are the only way in unix
<dh`>
what is the "correct thread" for a timer event?
<dh`>
well, signals are the only way in unix _for your own thread library_
<companion_cube>
Well if you have many threads and you want to preempt one of them, how do you deliver a signal to it? Kill?
<dh`>
I don't remember, posix messed it up and so it's at best complicated
<dh`>
but for preemption that doesn't make sense, you just preempt whoever's running
<dh`>
also for your own thread library it doesn't make sense to worry about it
<dh`>
if you have multiple system-level threads they're already preemptive
<dh`>
sorry, I'm explaining things in reverse order
<dh`>
case (1): you have a single-threaded traditional unix process, and you want threads in it. Implementing your own thread library is straightforward, just requires a few lines of asm for context switches. Making those threads preemptive is a matter of SIGALRM or SIGVTALRM or whatever other timer interface you have
<dh`>
case (2): you have system-level threads, which are already preemptive
<companion_cube>
I was confused indeed because we already have preemptive threads
<dh`>
case (3): you have system-level threads and you want your own lighter-weight (or "lighter-weight") threads on top, like ghc
<dh`>
that's already preemptive too, you don't need to add any more preemption
<dh`>
instead the hard part is dealing with when you get preempted inside your thread library
<dh`>
(or inside the GC, or other similar issues)
<dh`>
and looking in the scroll I think the original question was ill-formed anyway
<dh`>
:-|
<dh`>
the other factor is that you don't get multiple cpus/cores at a time without using the available system-level threads
myrkraverk has joined #ocaml
<companion_cube>
I indeed just use the existing threads, on the existing domains
myrkraverk_ has quit [Ping timeout: 252 seconds]
<discocaml>
<contificate> would still like to understand what OP meant
<discocaml>
<contificate> by preempting domains
<discocaml>
<contificate> that'd almost be like groups of threads running for a time slice, internally preempted, but really only one group runs at a time (switching between other members in the group), right
<dh`>
I would first have to understand what domains are in this sense (groups of system-level threads?)
<dh`>
(or single system-level threads?)
Serpent7776 has quit [Ping timeout: 252 seconds]
burley has left #ocaml [#ocaml]
<discocaml>
<contificate> my understanding is that it's a bit like duplicating the OCaml 4 setup
<discocaml>
<contificate> each domain gets its own runtime lock
<discocaml>
<contificate> with the advice being that you don't exceed the number of cores when creating domains
<discocaml>
<contificate> or `recommended_domain_count`
<discocaml>
<contificate> so it's like a unit of parallelism, has its own runtime lock, with system threads (acting as green threads) being switched between
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
<companion_cube>
Domains are a thread, a ticker thread, and a runtime slice with its own minor heap, afaik
<companion_cube>
Threads in one domain act like in ocaml 4, with no real parallelism, but domains can actually run in parallel to one another
<discocaml>
<contificate> but do they actually try to do per-CPU affinity
<discocaml>
<contificate> I guess not
<discocaml>
<contificate> so it's just basically taking the runtime lock, turning it into many (domain) locks, then those threads compete for their own domain lock, and the domains can share memory between each other
Haudegen has joined #ocaml
hazelmeow has quit [Remote host closed the connection]
hazelmeow has joined #ocaml
hazelmeow has quit [Remote host closed the connection]
hazelmeow has joined #ocaml
<discocaml>
<yawaramin> should be possible to set each domain's CPU affinity but i don't think anyone has bound to the C API for that
<companion_cube>
Just let the os do its thing I guess
<discocaml>
<dubious245> Remove the OS, no barriers between you are the metal.
<discocaml>
<dubious245> And*
bartholin has quit [Remote host closed the connection]
<discocaml>
<froyo> everyone wants to create a perfect world in which everything goes their way
<discocaml>
<froyo> no-one wants to play along :(
<discocaml>
<dubious245> Such is the way things work.
<discocaml>
<dubious245> :BlobSad:
<dh`>
dubious245: you sound like someone who's never written an OS :^)
<discocaml>
<dubious245> *Glances at my other monitor where I am trying to get a uart driver working.* I suppose that is technically true. For now.
jutty has quit [Quit: jutty]
jutty has joined #ocaml
<companion_cube>
I'd rather have an os and a working machine 😅