Replies: 1 comment 1 reply
-
|
• What would be the best way to share a text buffer between the
threads? I've seen something can be done with `ffi/malloc` but I
haven't thought of a way to lock the buffer so the memory is thread
safe.
• Is there a standard way to communicate between threads? Something
like an RPC-ish API. That's what I'm thinking of implementing using
threaded channels, at least.
I think you'll find the answer to both questions in the ev module. Specifically:
https://janet-lang.org/api/ev.html#ev/lock
https://janet-lang.org/api/ev.html#ev/rwlock
https://janet-lang.org/api/ev.html#ev/thread-chan
Note that using locks to coordinate threads is a time-honored tradition in systems programming, but also surprisingly difficult to get fully correct in nontrivial situations. Hence the emergence of higher-level abstractions such as channels and actors.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
bakpakin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm experimenting with designing a terminal text editor in Janet. This is my second attempt, with the previous one being stalled due to issues I had with... I think blocking reads?
Because of that, I'm experimenting with making a multithreaded design, with one thread for the editor logic, and another for I/O with the terminal (rendering UI and reading keyboard input).
What would be the best way to share a text buffer between the threads? I've seen something can be done with
ffi/mallocbut I haven't thought of a way to lock the buffer so the memory is thread safe.Is there a standard way to communicate between threads? Something like an RPC-ish API. That's what I'm thinking of implementing using threaded channels, at least.
Beta Was this translation helpful? Give feedback.
All reactions