companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.2.0 released: https://ocaml.org/releases/5.2.0 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
gzar has quit [Quit: WeeChat 4.3.2]
jabuxas has joined #ocaml
sailorCat has quit [Ping timeout: 268 seconds]
sailorCat has joined #ocaml
jabuxas has quit [Ping timeout: 268 seconds]
hannes_ has joined #ocaml
hannes has quit [Ping timeout: 264 seconds]
<discocaml_> <dinosaure> A solution is to make a new `Format.formatter` and ensure that this one is used by only one domain (the domain which prints out things).
<discocaml_> <dinosaure> I did a patch for `alcotest` recently about that where the user can use something else than `Format.std_formatter` for `alcotest`'s printers
<discocaml_> <dinosaure> And let something else be able to use `Format.std_formatter` for another purpose (like logs)
<discocaml_> <dinosaure> So the issue is not strickly related to `progress` but much more about `Format` which is completely not domain-safe
terrorjack has quit [Quit: The Lounge - https://thelounge.chat]
terrorjack has joined #ocaml
<companion_cube> it's domain safe if you don't use its global parts, right?
waleee has quit [Ping timeout: 264 seconds]
wbooze has quit [Remote host closed the connection]
mbuf has joined #ocaml
<discocaml_> <dinosaure> Yes. `std_formatter` can not be used across domains but you can have multiple formatters to `stdout` 🙂
<companion_cube> race conditions anyway, put a lock around it
bartholin has joined #ocaml
wbooze has joined #ocaml
mbuf has quit [Ping timeout: 256 seconds]
Serpent7776 has joined #ocaml
hannes_ is now known as hannes
<discocaml_> <kakadu18> Am I understanding correctly, that this will require a change in the progress's code base?
<discocaml_> <kakadu18> (I have some temptation to add a formatter argument to report function in progress, but don't know where it will lead me)
<discocaml_> <dinosaure> Depending on your code, a mutex is probably needed if the function which prints out is called by several domains.
<discocaml_> <dinosaure> Use another formatter is required if `std_formatter` is used by `progress` into a domain and something like `logs` uses it too in another domain.
<discocaml_> <dinosaure> And actually, you can specify the formatter you want to use with `Config.v`
<discocaml_> <dinosaure> So I don't think that we need to tweak `progress`. I don't have my computer now but, as far as I can tell, everything is here to avoid a data-race 🙂
<discocaml_> <kakadu18> Many thanks, I'm going to experiment with this.
<discocaml_> <kakadu18> I managed to get a desired result with a mutex. Thanks.
<discocaml_> <polytypic> Note that the Stdlib Mutex does not work well with fibers, because the Stdlib Mutex blocks the entire systhread/domain. I'm hoping to soon rewrite Domainslib internals and make it Picos compatible.
myrkraverk_ is now known as myrkraverk
czy has joined #ocaml
jyc has quit [Ping timeout: 255 seconds]
Duns_Scrotus____ has quit [Ping timeout: 256 seconds]
buoy49__ has quit [Ping timeout: 268 seconds]
delyan_ has quit [Ping timeout: 255 seconds]
pgiarrusso has quit [Ping timeout: 255 seconds]
Boarders_____ has quit [Ping timeout: 255 seconds]
abbe__ has quit [Ping timeout: 255 seconds]
caasih has quit [Ping timeout: 255 seconds]
Techcable has quit [Ping timeout: 272 seconds]
JSharp has quit [Ping timeout: 246 seconds]
jbowen has quit [Ping timeout: 272 seconds]
cbarrett has quit [Ping timeout: 256 seconds]
buoy49__ has joined #ocaml
Duns_Scrotus____ has joined #ocaml
caasih has joined #ocaml
abbe__ has joined #ocaml
jyc has joined #ocaml
jbowen has joined #ocaml
Boarders_____ has joined #ocaml
JSharp has joined #ocaml
delyan_ has joined #ocaml
pgiarrusso has joined #ocaml
Techcable has joined #ocaml
cbarrett has joined #ocaml
<companion_cube> Wait what
<companion_cube> It only blocks the thread
<companion_cube> Ah yeah, right. The / confused me
<discocaml_> <polytypic> Yes, I often use thread/domain, because it seems a lot of newcomers don't necessarily know about both of them. In the case of Domainslib, for example, Domainslib spawns domains. Using a Stdlib Mutex in a task running on Domainslib is typically a bad idea, because it prevents Domainslib from running other tasks on that domain.
<companion_cube> Yeah. I think Mutex still makes sense for short critical sections that won't contain IO or an await though
<discocaml_> <polytypic> Hmm... Well, sometimes you might not really have significantly better options conveniently available, but generally speaking, in the future, nobody should be using the Stdlib Mutex or Condition except in very specific circumstances when you really want to block the entire systhread. (Like in a scheduler when there is literally nothing else to do.)
<discocaml_> <polytypic> (Unless the Stdlib Mutex and Condition are fixed to actually allow a scheduler to run other fibers. Like with the Picos Mutex <https://ocaml-multicore.github.io/picos/doc/picos/Picos_sync/Mutex/index.html> and Condition <https://ocaml-multicore.github.io/picos/doc/picos/Picos_sync/Condition/index.html>.)
wbooze has quit [Remote host closed the connection]
gareppa has joined #ocaml
<companion_cube> Still don't see why a Mutex would be bad if there's no await inside
<discocaml_> <polytypic> You might be (and in the future you typically should be) running on a scheduler that could run other fibers while that mutex is owned by someone else. And not just the current owner, because mutexes typically are designed to be fair and so they hold a queue of awaiters, so there could be a queue of other fibers waiting for the mutex.
<discocaml_> <polytypic>
<discocaml_> <polytypic> The Stdlib Mutex, as it is, stops the entire systhread so that nothing can run on it (not even signal handlers written in OCaml).
<discocaml_> <polytypic>
<discocaml_> <polytypic> Now, perhaps you have a situation where the operations being run with a mutex are extremely short and the mutex is not highly contested. In such a case even the Stdlib Mutex could be ok. But, then, a "user space" (spinlock or a) mutex like the Picos Mutex would be preferable, because it can be faster and need not suffer from the problem of blocking the entire domain while being queued to become the owner of the mutex.
<discocaml_> <polytypic>
<discocaml_> <polytypic> Also, if the operations are very short, like adding a thing to a queue, then you probably would be better off using an off-the-shelf non-blocking data structure.
<discocaml_> <polytypic>
<discocaml_> <polytypic> So, TBH, I really don't see many good use cases for a pthread mutex (which is what the Stdlib Mutex is) that stops the entire systhread. If the operations are really short, it could be Ok, but then non-blocking data structure would likely be faster and better (better progress properties) and if it is long running (whether with await or not inside) then a user space mutex will be superior.
<discocaml_> <polytypic> IMHO, the Stdlib Mutex and Condition are kind of broken just like the Stdlib Domain in that they don't work cooperatively. They are fine for low level things to implement a more cooperative layer on top, but they just don't do the right thing in a future with effects based schedulers.
wbooze has joined #ocaml
<discocaml_> <polytypic> (And the same goes for Stdlib Lazy.)
<discocaml_> <polytypic> You might be (and in the future you typically should be) running on a scheduler that could run other fibers while that mutex is owned by someone else. And not just the current owner, because mutexes typically are designed to be fair and so they hold a queue of awaiters, so there could be a queue of other fibers waiting for the mutex.
<discocaml_> <polytypic>
<discocaml_> <polytypic> The Stdlib Mutex, as it is, stops the entire systhread so that nothing can run on it (not even signal handlers written in OCaml).
<discocaml_> <polytypic>
<discocaml_> <polytypic> Now, perhaps you have a situation where the operations being run with a mutex are short and the mutex is not highly contested. In such a case even the Stdlib Mutex could be ok. But, then, a "user space" (spinlock or a) mutex like the Picos Mutex could be preferable, because it can be faster and need not suffer from the problem of blocking the entire domain while being queued to become the owner of the mutex.
<discocaml_> <polytypic>
<discocaml_> <polytypic> Also, if the operations are very short, like adding a thing to a queue, then you probably would be better off using an off-the-shelf non-blocking data structure.
<discocaml_> <polytypic>
<discocaml_> <polytypic> So, TBH, I really don't see many good use cases for a pthread mutex (which is what the Stdlib Mutex is) that stops the entire systhread. If the operations are really short, it could be Ok, but then non-blocking data structure would likely be faster and better (better progress properties) and if it is long running (whether with await or not inside) then a user space mutex will be superior.
jabuxas has joined #ocaml
<discocaml_> <polytypic> But to reiterate what I said previously... Currently better options (non-blocking data structures or user space mutexes) aren't necessarily conveniently available. So, don't worry too much about using the Stdlib Mutex, but be aware that you probably want to use something else in the future.
czy has quit [Ping timeout: 255 seconds]
quernd801 has joined #ocaml
quernd80 has quit [Ping timeout: 264 seconds]
quernd801 is now known as quernd80
quernd80 has quit [Read error: Connection reset by peer]
quernd80 has joined #ocaml
<companion_cube> Please stop editing details on this channel, it's a lot of text on the irc side 😅
<companion_cube> Well if I want to update a couple things, a Mutex is still the simplest thing for now
<companion_cube> I know kcas is what you think should replace it but sometimes simple is good too
gareppa has quit [Quit: WeeChat 4.1.1]
<discocaml_> <polytypic> Sorry, I forgot that the edits are sent as separate messages for the IRC users. Will try to remember to use a separate editor in the future on this channel.
<companion_cube> no worries
<companion_cube> (my point is, anyway: if you don't have cooperation within the critical section then I'm not sure why Mutex is bad)
<discocaml_> <polytypic> > kcas is what you think should replace it
<discocaml_> <polytypic> Well... For a lot of things, yes, but I wasn't really thinking of that here specifically. Just that the Stdlib Mutex and Condition don't currently do the right thing when it comes to effects based schedulers which I expect to become the norm in OCaml in the future.
<companion_cube> I 99% agree on conditions! just not on mutex :p
<companion_cube> (*in some specific cases)
dawids_ has joined #ocaml
dawids_ has quit [Remote host closed the connection]
mbuf has joined #ocaml
jabuxas has quit [Ping timeout: 246 seconds]
mbuf has quit [Quit: Leaving]
<discocaml_> <yawaramin> would it be possible to tell the IRC bridge to post edits in the form of diffs or `s/.../.../` rather than reposting the new version of the entire message?
<companion_cube> not that I know of
waleee has joined #ocaml
<discocaml_> <sim642> Computing diffs as sets of sed replacements is an interesting challenge
wbooze has quit [Remote host closed the connection]
jabuxas has joined #ocaml
walee_ has joined #ocaml
waleee has quit [Ping timeout: 264 seconds]
walee_ has quit [Ping timeout: 252 seconds]
<discocaml_> <akhilindurti> is there a proposal to add a function composition operator to the stdlib? i.e. `('a -> 'b) -> ('c -> 'a) -> 'c -> 'b`
<discocaml_> <sim642> Fun.compose exists since OCaml 5.2
<discocaml_> <sim642> Not an operator though
jabuxas has quit [Ping timeout: 268 seconds]
waleee has joined #ocaml
wbooze has joined #ocaml
jabuxas has joined #ocaml
torretto has quit [Ping timeout: 260 seconds]
torretto has joined #ocaml
waleee has quit [Quit: WeeChat 4.1.2]
szkl has joined #ocaml
Serpent7776 has quit [Ping timeout: 255 seconds]
Tuplanolla has joined #ocaml
waleee has joined #ocaml
bartholin has quit [Quit: Leaving]