I'm really new to Erlang and currently I have problems writing a reader-writer program in Erlang. Basically, a shared memory location can be concurrently read by any number of tasks, but when a task must write to the shared memory location, it must have exclusive access. My thought would be to spawn reader/write methods to different processes and in those methods just print out something like "Reader reading"/"Writer writing".
However, the usage of semaphore/mutex really bugged me and I have no background in multithreading/concurrency. Can anyone please give some clues how to write such program?
Mutexes and Semaphores are just a way of defining synchronization points between two concurrent processes/threads. In erlang these are mostly replaced by sending and receiving messages between erlang processes. An idiomatic way to do this in erlang would be to:
The message box for your data process will ensure that nobody else can write to the data at the same time as everyone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With