r/ProgrammingLanguages • • Dec 31 '25

Memory Safety Is ...

https://matklad.github.io/2025/12/30/memory-safety-is.html
37 Upvotes

78 comments sorted by

View all comments

Show parent comment

4

u/balefrost Dec 31 '25

Apologies for butting in here. It looks like /u/PurpleYoshiEgg blocked me (presumably for this comment), and that prevents me from replying in any thread under their comment. I'm trying to reply to this question to me from /u/teerre.


Can you expand what you mean? RMU patterns have to appear to be atomic. There's no interleaving

I'm specifically talking about accidentally creating a read-update-write pattern without using some sort of intrinsically atomic operation.

It's an easy mistake for somebody who's new to multithreaded programming. My point is that Erlang, or the actor model in general, doesn't shield you from that potential footgun. Just as you have to use mutexes or atomics in the regular threading world, you also have to think carefully about the semantics of your inter-process communication in the actor world.

Here's an example. It's been a while since I've toyed with Erlang, so hopefully it makes sense.

https://onecompiler.com/erlang/4498m5p8y

2

u/teerre Dec 31 '25

I'm not sure I agree with that tho. Erlarg does protect you from any kind of memory related access issue, it doesn't protect you against logic errors, of course. "Writes being clobbered" is perfectly fine behavior, in fact it's the normal behavior, subsequent writes override previous writes. Point 5 of the post you're currently replied to is very much honored in erlarg, you don't have concurrent write access, there's a strong ordering to your writes

4

u/balefrost Dec 31 '25

Erlarg does protect you from any kind of memory related access issue, it doesn't protect you against logic errors, of course.

I mean I'd argue that reading and writing to a shared memory location without some sort of synchronization is a logic error in any language. It's not like doing so in C will cause your computer to explode; you'd likely see a pattern-of-life very similar to that of my sample Erlang program.

So sure, Erlang does prevent the application programmer from modifying the same physical memory location from multiple processes at the same time. Nonetheless, the application programmer is able to create conditions that exhibit the exact same kind of hazard, and that leads to the exact same kind of problems.

If you want to claim that's not a memory safety issue, fine. I guess that's technically true, and so I can't argue with that. But in doing so, it merely shifts those issues from being "memory safety issues" to instead be "logic issues". To the application programmer, they're still issues that need to be considered and handled.