A Brief Cogitation on Thread-Safe Memory Access

Hey, I’ve got an idea. Let’s you and me write a couple programs and share data between them. To share the data, we’ll both open a file. Now, we’ll just scribble bits we want to share into the file and read them out as we need them.

“Bad idea,” you say?

“Very likely to result in data corruption,” you say?

“There’s a reason we have database engines,” you say?

“Sure, but only if we do it in a very well-defined structure, such as ‘Only one program can write in, only one can read out, and the file is a stream, not random-access’”, you suggest?

… We should all probably stop thinking multiple threads touching the same memory without either programmer-constraining disciplines or resource-consuming protections is ever something we should do.