Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

producer-consumer using assignment

I am interested in finding if producer-consumer problem when there are multiple produce and multiple consumer be solved without using assignment i.e., using functional style of programming? How?

Producer-consumer problem

Thanks

like image 897
StackUnderflow Avatar asked May 23 '26 05:05

StackUnderflow


2 Answers

Yes, you can do it quite nicely with message passing in Concurrent ML. Don't be put off by the age of the system; John Reppy's book and papers are excellent guides to the topic. Beautiful stuff!

like image 180
Norman Ramsey Avatar answered May 25 '26 11:05

Norman Ramsey


Having multiple threads necessarily requires impure (non-functional) actions. Pure functional programming considers your application to be the evaluation of a function. The concept of concurrently evaluating two things and passing data between them is not meaningful within this framework.

Although one can evaluate multiple parts of a function in parallel, as in Haskell's ``par operator, this is not the same as the producer-consumer problem, and as such I don't think you'll be able to solve it in a functional way.

like image 20
bdonlan Avatar answered May 25 '26 11:05

bdonlan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!