« first day (1613 days earlier)      last day (3350 days later) » 

7:00 PM
@QuestionC lol volatile and threads.
 
@Puppy I'm the one saying you don't need volatile for thread safety.
You take issue with that?
 
well, you do need it.
it's just far from enough.
 
Sorry, that sounded stand-offish, but you know what I mean.
I really don't think you do need it. If you have a compiler that optimizes away references to variables with external linkage, I'd call that compiler broken.
It would certainly break a ton of code.
 
the compiler is well within it's rights to do so if it's not volatile.
 
@QuestionC I'd call that code broken.
 
7:04 PM
the compiler has explicit guarantee by Standard that it is the only thread running, and therefore no other thread can change the value, unless there's a bunch of synchronization (which includes volatile).
 
Man, I don't know if I want to go in there.
 
Round two... FIGHT!
 
@QuestionC I've just shown that it is completely allowed to.
 
If a variable has external linkage, I would call that a potential for change detectable by the implementation.
 
@QuestionC That's not how it works, buddy.
 
7:08 PM
Well, by y'alls stance, most threaded code out there is hugely broken, and the standards are not written to take into account the way people code. That's my real issue.
We pass pointers around threads all the time and every optomizer speech talks about the pains they take to deal with the fact that they don't know whether memory is being modified by someone else.
 
@QuestionC Ah, but who is doing the changing? Certainly not the currently running thread (assuming, say, no external function calls). Therefore, it's not changing, if it's not volatile.
 
@QuestionC Yes, a lot of multi-threaded code (and even single-threaded code, for that matter) is horribly broken. Move along. Nothing new here.
 
I mean virtually all multithreaded code.
 
@QuestionC Right, but you can't be reading them whilst someone else is writing them without a data race or volatile.
 
We're talking every textbook example of producer consumer.
 
7:10 PM
all of them use volatile.
 
@QuestionC You don't have to mark everything volatile. It depends what you're doing with the data. If it's being read from in one thread that previously wrote to it, but you've written to it in another thread in between those two operations, you should mark the variable volatile.
 
or equivalent-in-this-case compiler intrinsics.
 
@QuestionC That's a different issue (aliasing). There's it's not a matter of someone else modifying the data, it's the possibility that (for example) two pointers to the same place are passed to a single function, so that function is both reading from and writing to the same memory, so it needs to read from memory (rather than, say, a register) just because somebody might pass the same (or overlapping) pointers.
 
@LightnessRacesinOrbit Let's say I have a synchronous queue object. It's created as empty in Consumer.cpp. The only other interaction with it in that file is to pull elements off of it.

Producer.cpp pumps elements into the queue forever.

You're saying that queue has to be declared volatile if I understand correctly. And I take huge issue with that.
 
Files/TUs really are a red herring.
 
7:17 PM
no, it doesn't have to be declared volatile.
if you call a function on the queue, that function could perform volatile reads/writes to the queue.
which is exactly what they do.
 
The whole shebang is the logical machine, the compiler and the linker. And unless you take pains to say "Hey, this is literally impossible to access outside this compilation unit", you really can't require the use of volatile for dealing with threaded programming.
 
compilation units are irrelevant.
 
And it's hard to think of cases where you can trick the compiler like that. Just registers, memory mapped IO.
Cetainly not threads talking to each other through normal C linking rules.
 
C linking rules don't say anything about threads.
it's impossible to implement any concurrent function or structure without volatile in the stack.
 
0
Q: Should I mark variables as variable if they are shared across threads?

Lightness Races in OrbitI am writing to a variable in one thread and reading from it in another. I have been told that volatile is completely useless for this and that I do not need to use it in this day and age unless I am working with hardware. Should I use volatile in this case? int x = 0; void thread1() { while...

Reviews appreciated.
 
7:21 PM
variables as variable
 
*variables as volatile
 
that's a different thing
declaring a variable as volatile, and making volatile reads/writes to it, are different things.
 
I see code that uses CRTP to let a base type figure out what its most derived type is. Why use that over std::type_info?
 
because it's compile-time and therefore completely superior in every way
CRTP gives you an actual type and type_info is nothing much of use.
 
7:26 PM
Why is type_info not that useful? Don't both give you the type?
 
right, except one is an actual type that you can inspect, you can create objects of, you can call functions on, etc.
whereas type_info is just some object in memory and there are virtually no useful operations on it.
 
Ok. Oh wow it also seems that type_info doesn't work if there are no virtual methods in the derived class
 
well, the available operations on type_info are basically nothing.
the operations on T are everything.
 
@Puppy Better? I put a new bit in the bootnote
 
7:29 PM
bootnote
You are off your game today
 
Oh boy, Kerrek answered it.
 
@EtiennedeMartel ...and gave a much better answer. Using volatile in this situation takes a lot for granted that isn't actually specified in the standard, up to, and including, writes in one thread necessarily being visible in another thread within a reasonable period of time (or ever, really). Worse, using it will seem to work on x86 (because of its strong cache coherence model), but can/will fail on other hardware.
 
@Pris It works fine, but it’s not polymorphic.
 
I'm bored
Entertain me /cc @Rapptz
®åππ™∑
ª€ƒƒƒ®€æ, nice
 
@LightnessRacesinOrbit why on earth doesn't your post mention that accessing an object between two threads where at least one is a writer is undefined behavior, no matter if it is through a volatile object or not?
 
7:38 PM
@LightnessRacesinOrbit all you need now is a link to atomic on cppreference
 
that answer is really really bad in my opinion
and I mean.. really bad
 
Ø_ø
 
"This answer does not address one specific thing therefore it is the worst answer I've ever seen" -- refp 2015
 
@FilipRoséen-refp It's perfectly well-defined if they're atomic reads/writes.
 
@Puppy yes, and you know that I know that.
 
7:40 PM
no I don't.
 
there's a silver lining to the thing with kids DDOS-ing the CS match I guess
 
@Puppy well, you should - and now you do
 
my team was losing and I got all my skins back
dodged a bullet
 
I'll forget it soon enough
 
@Puppy no worries.
 
7:42 PM
Best part about that question is how Kerrek hijacked it.
More fun than this argument over here.
 
> Why aren't koalas actual bears? The don't meet the koalafications
/cc @Nooble @sehe
 
Wow, everyone's missing the point so completely
 
@Rapptz Looks like a Metacritic user review, really.
 
I'm trying to dispel the myth that volatile is practically a no-op
It is clearly not a no-op
I'm not saying yeah you should definitely use it man it's hip and cool and edgy
And I concede that it's redundant when the mutexes are in place
 
7:47 PM
The myth you have defined on your own?
 
No, the myth that people keep trying to convince me of in ridiculous comment arguments all over SO
Y'know, the reason I wrote this Q&A in the first place?
 
Do you have some examples?
 
@LightnessRacesinOrbit you should rephrase the question, or completely change the answer
@LightnessRacesinOrbit without talking about the UB involved when accessing an object between threads without any synchronization the answer is moot.
 
I'm honestly not sure why you're complaining about this considering there's a whole paragraph devoted to it.
Did you read it?
 
Too long
 
7:50 PM
I feel like most people read the first word and just downvoted.
 
@Rapptz I read the entire post; "It cannot make concurrent reads and writes to an object safe" is not strong enough wording
 
The first word is too long; didn't read.
AHAHA GOT IT
 
Jesus.
You're awful dude.
 
Because the first word is actually "tl;dr"
 
I'm actually a little impressed at this level of pedantry.
 
7:51 PM
no, it's not pedantry
 
IM SO FUNNY !!!11!
 
The first word was "Yes" before he edited it.
 
the problem is that the rest of the post has no meaning because of that "little" thing
 
You can't handle my funniness
 
Write your own answer and stop bitching.
 
7:52 PM
@Rapptz ignore me and stop replying.
 
Make sure to make it all bold and in h6 so the message gets across.
 
I'd upvote that. Just to piss LRiO off
 
I'm off to buy some smokes.. peace
 
No wonder you're so grumpy.
 
@Rapptz Yeah :(
I might just delete the entire fucking thing. Not because my first revisions were not accurate — I perfectly accept that. But everyone's focussing on entirely the wrong thing and ruining the point I was trying to make. :(
 
7:53 PM
I didn't vote you up or down.
 
Surely partially my fault for not getting it right first time but I think there's something else at play here
 
I upvoted Kerrek though because it was funny to me a bit.
 
Yeah, shit like that.
 
@LightnessRacesinOrbit What was the point you were trying to make?
 
@LightnessRacesinOrbit it ok bby, i hold u
 
7:54 PM
I read your answer though.
 
@Jefffrey Scroll up and read the fucking conversation you numpty
Fucking sick of this now
7 mins ago, by Lightness Races in Orbit
I'm trying to dispel the myth that volatile is practically a no-op
THAT'S IT
 
It seems a lot like "Should I use an std::string when I need an integer? No you should not."
 
@Jefffrey what the hell where did you get that nonsense from you unimaginative cretin
I take it back
 
I'm trying to dispel the myth that std::string is really an integer
 
He's bored.
 
7:55 PM
you're very imaginative
because you entirely made it up
 
Didn't you see his splerg attack earlier?
 
no I missed that one
 
I've asked you if you could please show me where this "myth" is coming from
No answer whatsoever.
I'm sorry, but what should I think about all this?
 
Truly an informed voter over here.
 
Just to be clear, the conversation was about whether making his shared variables volatile would potentially fix a guy's threaded program where he didn't understand the behavior.
 
7:57 PM
Considering all candidates and conspiracies.
 
Is there a way to increment a counter based on when certain types are created?
int animal_types=0;
struct Animal {}
struct Cat : Animal {} // animal_types==1
struct Dog : Animal {} // animal_types==2
 
Vote for Kerrek SB 2015.
 
@Pris No there isn't, and thank God for that because that's a tremendously dumb and useless thing to do.
 
I don't even want to know why you would want to do that
 
@LightnessRacesinOrbit I think that Herb Sutter or somebody has nicely demonstrated that for threading, volatile is useless.
 
7:59 PM
@Jefffrey to get a unique id for a set of types
5
Q: Unique type ID in C++

FelicsI need to have an unique ID for any type in C++ for a variant type. Is this code reliable for getting the ID? I don't care to have same ID for same type between multiple runs. Sorry for typos/formatting, I wrote the code on my phone and tested on Ideone. #include <iostream> struct Counter { ...

 
Why do you need a unique id?
 
@Pris XY (regarding the earlier question)
 
There are some ways shown in that answer but I don't like em really
 

« first day (1613 days earlier)      last day (3350 days later) »