News for hackers. Stuff that matters.
Re:When the Simplest Concurrent Program Goes Against All Int... by hedin_hiervard on Saturday January 18, 2025 @04:36AM (#42747091)
I was once asked a very similar problem during a job interview for a position of a software engineer. I was offered to solve it on a piece of paper or orally. We ran out of time and they offered me to take it home. I did and I spent a few hours thinking about it. Google and ChatGPT were not able to produce better results than the intuitive answer, so I built a test program that confirmed the weird behaviour. After meditating for a few hours I was able to find the correct answer and I was indeed fascinated by this. Do you also think it's too much for a usual interview?
Re:When the Simplest Concurrent Program Goes Against All Int... by kunley on Saturday January 18, 2025 @05:05AM (#42747224)
Kudos for solving this. And yes, this is too much for a job interview.
Re:When the Simplest Concurrent Program Goes Against All Int... by burfle on Saturday January 18, 2025 @12:49PM (#42749984)
I don't think this an unreasonable puzzle for a role that involves problem-solving or security.

You can read the code, figure out what primitives you have, translate the problem into something simple (I like card and board games), then map it back.

Problem: two processes each do this ten times: - read the counter - do any number of other things in other processes - write back what you read, plus one.

Game: You have two piles of cards. Each card costs 1 move to play, but lets you discard any number of cards from other piles at the same time.

Solution: play one red card, discarding everything but one blue card. Play the single remaining blue card, discarding the leftover red cards.

Back: process 1 reads, process 2 runs 9 steps, process 1 writes, process 2 reads, process 1 finishes, process 2 writes.