Answer the question
In order to leave comments, you need to log in
Why is functional programming considered thread safe?
Why is FP considered thread-safe? And if you need to store general information in the application's memory, for example, a message queue or something like that. What approach is used in OP to do this?
Answer the question
In order to leave comments, you need to log in
An FP program does not store a state that threads can change concurrently. And in pure FP, naming should be immutable. That is, in pure FP the construction
something = 2
something = 3
illegal, illegal. If something = 2
, then it is forever and cannot suddenly become =3
. With this approach, threads cannot access the same place in memory at the same time trying to change the state variable. To exchange data between threads, you can only use special primitives protected under the hood by operating system synchronization mechanisms (like Mutex or Atomic). For example, a message queue can be represented by a list that cannot be manipulated directly, but only by Queue.Put() Queue.Get()
. And in the implementation of these methods, locks from parallel access to memory are already protected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question