3 ms·
> Well, think of it this way, if you're not into compilers wouldn't you expect your code to run as written? But the possible and actual interleavings aren't wr
by chrisseaton 5y ago
> Well, think of it this way, if you're not into compilers wouldn't you expect your code to run as written?
But the possible and actual interleavings aren't written in the program - so how can I guess what the user needs from what's written?
- Retric 5y agoConsider the reverse. What if the interleaving was undesirable, would you like some way to be informed that it’s impossible so you don’t have to reason about it? When trying to reason about code, finding somethings that looks like a bug but isn’t can result in a lot of wasted effort.
- chrisseaton 5y ago> What if the interleaving was undesirable, would you like some way to be informed that it’s impossible That's like synchronised in Java or any other kind of atomic block or serialising block - that's already a thing.
- Retric 5y agoThat information is moving in the wrong direction. I don’t want the programmer to be telling a compiler what to do, I want the compiler to inform the programmer what it did.
- chrisseaton 5y ago> That information is moving in the wrong direction. You set the direction not me! You asked me 'would you like some way to be informed that [the interleaving is] impossible'. Yes... and the user gives me that information through a synchronised block. If they don't tell me they want an interleaving to be impossible then why should I not make it possible? There are countless other interleavings I make impossible or possible when I do any trivial compiler task such as scheduling. Should I consult the user on all of them? I don't think you'd like all the questions you'd get!
- Retric 5y agoInforming the user isn’t about what you did, it’s about the user having some way of knowing what you did. At least compilers give you assembly code to look at, CPU’s are little better than black magic from a programmers perspective.
- chrisseaton 5y agoThe user can dump the compiler output and intermediate structures if they want. Or they could program against the spec and not worry.
- kaba0 5y agoCheck the generated machine/byte code?
- overgard 5y agoThe answer is: don't guess.
- chrisseaton 5y agoWe don't - and in this example we'd combine atomics rather than guess that the user wanted the thread to yield between them, since they never told us that.
- overgard 5y agoThat's not true, you are making a guess: that the user doesn't care about the intermediate stage. Not guessing would mean generating the code as specified. It doesn't matter if you think its a bad idea, the whole ethos of C is trust the programmer.
- chrisseaton 5y ago> you are making a guess: that the user doesn't care about the intermediate stage That's not a guess - the user didn't put anything in between them so we know they haven't required them to be separate. Keeping them separate would be making the guess - a guess that they need them to be separate. Why should we invent that constraint when the user never wrote it? > Not guessing would mean generating the code as specified. We are generating it as specified - nothing in the specification says atomic actions have to be run independently. Why should I invent extra constraints that don't exist in the specification?
- overgard 5y agoOh come on, that language lawyering is sophistry. If I write 4 instructions that are "atomic" I expect 4 instructions. If I end up with one, they werent really "atoms" were they? I do not expect what you just said. I may think, gee, perhaps I don't need 4 instructions, but what you are doing is undeniably changing the meaning of the program, even if you think it's close enough. The fact that there's an article about this tends to agree with me that most people think: wtf happened?