5 ms·
Use multiple processes, and then your code works across multiple machines too (and better across NUMA machines). Threads are simply a bad idea.
by rwmj 7y ago
Use multiple processes, and then your code works across multiple machines too (and better across NUMA machines). Threads are simply a bad idea.
- dna_polymerase 7y agoShared memory is still an issue though. To my knowledge there is no convenient way to share memory between processes in OCaml. That said, you are right, threads are horrible.
- lifty 7y agoCorrectly implemented concurrency/parallelism primitives are not a bad idea. I am thinking along the lines of Clojure/Erlang/Go. They make life more enjoyable.
- newen 7y agoWhat is it called when you live in an environment where X is not available and so you convince yourself that X is a bad idea?
- rwmj 7y agoI used shared memory concurrency all the time, you're simply wrong.
- pjmlp 7y agoModern security exploits and application crashes due to state corruption have proven that while threads were an enticing idea, they aren't something that we should keep around if we care about security and application stability. This applies to all programming languages, not only OCaml, hence why everyone is moving away into other concurrency models anyway.
- amelius 7y agoThere are many applications where these kind of security issues don't apply.
- pjmlp 7y agoSuch as? Every application should strive for proper quality, just like in other industries.
- amelius 7y agoFor example: embedded applications, or when I'm the only one running trusted code on my computer. Think also of scientific computing. If you insist on networked solutions: database servers. Also: "multicore + purely functional style" is just as clean as "multiprocess + purely functional style", but ... the latter is less efficient because of communication overhead.
- pjmlp 7y agoUnless you manage to do any kind of work without IO, there is always a security risk. And if that is irrelevant to you, there is still the application stability and memory consistency to ensure data is being handled in a memory consistent state. Fortran is a good example on how to do scientific computing without low level threads.
- amelius 7y agoYes threads should be used with extreme caution, that's why I advocate using a functional programming style. But you still want the performance of multicore. It's not one or the other (but with OCaml it unfortunately is).
- newen 7y agoYou have two matrices, with allocated memory A and B, that you want to multiply and store to allocated memory C, as efficiently as possible using 8 cores. How do you do this without threads exactly?
- pjmlp 7y agoVector instructions or GPGPU.
- newen 7y agoAssume no GPU. Vector instructions will only use one core at a time.
- pjmlp 7y agoWe are in 2019, even low level microcontrollers have dumbed down GPUs. Plus I already answered your questions, not moving goal posts here.
- detaro 7y agoAnd will spend more time shuffling data through their horribly bottle-necked memory interfaces than the CPU would take handling the matrix operation, especially if the GPU is already used for graphics. Multi-core systems and tools that can use them are valuable and very much reality right now.
- amelius 7y agoOne of the strengths of functional programming is using structurally shared immutable data structures. You can't use this approach efficiently if you don't share a heap with other processes. Converting everything to a shared byte array (or similar) mostly ruins the usefulness of the programming language, and also makes GC impossible.