7

I am reading through "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and it says that:

All race conditions, deadlock conditions, and concurrent update problems are due to mutable variables.

Functional programming languages do not allow variables to be mutable. I can see why race conditions and concurrent update problems require the existence of mutable variables. However, I don't see how deadlock conditions require mutable variables.

Can someone help me address my knowledge gap? Or is the author of the book incorrect in his statement about deadlock conditions?

asked Nov 24, 2022 at 18:57
2
  • "Functional programming languages do not allow variables to be mutable." - I think you'll find that, ultimately, the only data that is useful, is mutable. Functional languages do allow variables and other data to be mutable - there was just a lot of hype a few years ago about how the supposed answer to everything was immutability. Commented Nov 24, 2022 at 21:54
  • It's quite possible to write a program that deadlocks itself without mutable variables. Depending on your locking mechanism, lock(a); lock(a); may be sufficient for a thread to deadlock itself. Commented Nov 25, 2022 at 9:20

1 Answer 1

14

The quote is correct in principle. If you don't have any mutable state or side effects then you don't need to lock anything and without locks you don't get deadlocks.

But in reality, most programs, functional or otherwise, do need to operate with mutable state or side effects. Functional languages might not have mutable variables, but they might still need to interact with databases or files or IO resources, which is where locks may become necessary

answered Nov 24, 2022 at 19:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.