!!!!Static variables are not multithread!!!!!
-
...the butler. Yes! The butler! The multiple threads, all of them, they came from his jacket - he did it, not me, he did it!
Shog9
drifting along with the tumbling tumbleweeds...
I'm starting to worry about you now Josh. :rolleyes:* *:rolleyes: to the fact that I'm only starting now. Regards, Brian Dela :-)
-
I'm starting to worry about you now Josh. :rolleyes:* *:rolleyes: to the fact that I'm only starting now. Regards, Brian Dela :-)
Sorry, forgot to give him is medication last night :rolleyes: The tigress is here :-D
-
Althought static variables are not recommended, I always believed there was no problemm to use them in particular situations. However I discovered Visual C implementation of STATIC VARIABLE INITIALIZATION IS NOT THREAD SAFE. I believe most programmers ignore this problemm and they programms are critically flawed. For example: void Function () { static int x = g (); ... } void Function () { static CString y; ... } Most programmers believes x and y are initialized when programm starts, but this is wrong. They are initialized on the first call to Function (). Visual C uses a static flag to check wheather the variable was initialized. There's no critical section implemented, so if this function is called by two threads at the same time, the variable may be initialized twice!!!! In the first example, function g may be called twice, what's wrong!!! The second example is even worst. The constructor for variable y may be called twice!!!! ------- Disasambly of first example ------- 16: static int i = g (); 00418F58 xor eax,eax 00418F5A mov al,[?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F5F and eax,1 00418F62 test eax,eax 00418F64 jne f+3Fh (00418f7f) 00418F66 mov cl,byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F6C or cl,1 00418F6F mov byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)],cl 00418F75 call @ILT+0(g) (00401005) 00418F7A mov [i (00438e78)],eax 00418F7F ... --- The rest of function code ---
-
Sorry, forgot to give him is medication last night :rolleyes: The tigress is here :-D
What have you done?
"Póg mo thóin!"
"One of the most important things you learn !rom the internet is that there is no ‘them’ out there. It’s just an awful lot of ‘us’." -Douglas Adams
Jonathan 'nonny' Newman Homepage [www.nonny.com] [^] Bob Chum Dev site [^] -
Confucius say, use correct forum, lest ye want some ancient oriental happenings on your izass! :) Jeremy Falcon
Now, I admit I hardly come here anymore, so maybe the rules have changed, but this is not a programming question, the guy is trying to *discuss* something he has *discovered*. How is that wrong for the lounge of a programming site ? Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
-
Now, I admit I hardly come here anymore, so maybe the rules have changed, but this is not a programming question, the guy is trying to *discuss* something he has *discovered*. How is that wrong for the lounge of a programming site ? Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
Think categorically! What if someone wants to search posts for static variables, etc.? Where they gonna look? Personally, I'd choose the Visual C++ forum. Jeremy Falcon
-
Think categorically! What if someone wants to search posts for static variables, etc.? Where they gonna look? Personally, I'd choose the Visual C++ forum. Jeremy Falcon
Think categorically ? Personally, I'd have thought some discussion on the topic and the suggestion that the guy write an article if it's not already covered somewhere would have been more helpful. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
-
Think categorically ? Personally, I'd have thought some discussion on the topic and the suggestion that the guy write an article if it's not already covered somewhere would have been more helpful. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
Like that can't happen in the Visual C++ forum! Also, is it just me or do you seem a little uptight? What gives? Jeremy Falcon
-
Like that can't happen in the Visual C++ forum! Also, is it just me or do you seem a little uptight? What gives? Jeremy Falcon
Jeremy Falcon wrote: Like that can't happen in the Visual C++ forum! I would have thought it was less likely to happen, yes. Jeremy Falcon wrote: Also, is it just me or do you seem a little uptight? What gives? Well, I have to admit that this is true. We are trying to buy a new house. I did a loan application on the phone on monday. All went well until the woman says 'now your $6,000 credit card needs to be under the limit before I can process this'. I don't HAVE a $6,000 credit card, or so I thought. My wife overheard me protesting that said card did not exist, and said 'give me the phone.' The bank rejected our application based on how my wife has handled her secret credit card. It didn't help that I couldn't call the bank again because the phone was cut off. Guess who in our house pays that bill ? Also, the shops across the road used to have a phone box, but it was removed at the shops request, because drunks used it at 2 am and made a mess of the shops. It's going back up. In front of my house, by my driveway. I've called the provider, and they basically said that they had no obligation to inform me, I can't stop them, and I should go away and let them destroy the property values of the house I'll live in for a while yet, thanks to my wifes secret credit card. So yes, I admit to being stressed and grumpy. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
-
Jeremy Falcon wrote: Like that can't happen in the Visual C++ forum! I would have thought it was less likely to happen, yes. Jeremy Falcon wrote: Also, is it just me or do you seem a little uptight? What gives? Well, I have to admit that this is true. We are trying to buy a new house. I did a loan application on the phone on monday. All went well until the woman says 'now your $6,000 credit card needs to be under the limit before I can process this'. I don't HAVE a $6,000 credit card, or so I thought. My wife overheard me protesting that said card did not exist, and said 'give me the phone.' The bank rejected our application based on how my wife has handled her secret credit card. It didn't help that I couldn't call the bank again because the phone was cut off. Guess who in our house pays that bill ? Also, the shops across the road used to have a phone box, but it was removed at the shops request, because drunks used it at 2 am and made a mess of the shops. It's going back up. In front of my house, by my driveway. I've called the provider, and they basically said that they had no obligation to inform me, I can't stop them, and I should go away and let them destroy the property values of the house I'll live in for a while yet, thanks to my wifes secret credit card. So yes, I admit to being stressed and grumpy. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
Christian Graus wrote: The bank rejected our application based on how my wife has handled her secret credit card. Christian, [sarcastic]Thanks a lot[/sarcastic] Now I need to go apologize to my wife for insisting that she was the worst money manager in the world. Hope your 'luck' turns around. -Jack
There are 10 types of people in this world, those that understand binary and those who don't.
-
Christian Graus wrote: The bank rejected our application based on how my wife has handled her secret credit card. Christian, [sarcastic]Thanks a lot[/sarcastic] Now I need to go apologize to my wife for insisting that she was the worst money manager in the world. Hope your 'luck' turns around. -Jack
There are 10 types of people in this world, those that understand binary and those who don't.
Jack Handy wrote: Now I need to go apologize to my wife for insisting that she was the worst money manager in the world. LOL - thanks for the first bright moment in this fiasco. Actually, we've gone to another bank and I'd run our chances at about 65% to get the house still. Either way, it's been a harrowing week. I went home on Wednesday and went to bed at 6:00. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
-
Think categorically ? Personally, I'd have thought some discussion on the topic and the suggestion that the guy write an article if it's not already covered somewhere would have been more helpful. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
I browse the Visual C++ forum to see what people are doing and maybe even anticipate problems/solutions that I haven't dealt wit hyet. So I would suggest the Visual C++ forum is the appropriate place for the post. Elain :rose: The tigress is here :-D
-
Althought static variables are not recommended, I always believed there was no problemm to use them in particular situations. However I discovered Visual C implementation of STATIC VARIABLE INITIALIZATION IS NOT THREAD SAFE. I believe most programmers ignore this problemm and they programms are critically flawed. For example: void Function () { static int x = g (); ... } void Function () { static CString y; ... } Most programmers believes x and y are initialized when programm starts, but this is wrong. They are initialized on the first call to Function (). Visual C uses a static flag to check wheather the variable was initialized. There's no critical section implemented, so if this function is called by two threads at the same time, the variable may be initialized twice!!!! In the first example, function g may be called twice, what's wrong!!! The second example is even worst. The constructor for variable y may be called twice!!!! ------- Disasambly of first example ------- 16: static int i = g (); 00418F58 xor eax,eax 00418F5A mov al,[?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F5F and eax,1 00418F62 test eax,eax 00418F64 jne f+3Fh (00418f7f) 00418F66 mov cl,byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F6C or cl,1 00418F6F mov byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)],cl 00418F75 call @ILT+0(g) (00401005) 00418F7A mov [i (00438e78)],eax 00418F7F ... --- The rest of function code ---
Oh, my god... How horrible!!! You need to be drugged. :) Thanks, Wes
-
Althought static variables are not recommended, I always believed there was no problemm to use them in particular situations. However I discovered Visual C implementation of STATIC VARIABLE INITIALIZATION IS NOT THREAD SAFE. I believe most programmers ignore this problemm and they programms are critically flawed. For example: void Function () { static int x = g (); ... } void Function () { static CString y; ... } Most programmers believes x and y are initialized when programm starts, but this is wrong. They are initialized on the first call to Function (). Visual C uses a static flag to check wheather the variable was initialized. There's no critical section implemented, so if this function is called by two threads at the same time, the variable may be initialized twice!!!! In the first example, function g may be called twice, what's wrong!!! The second example is even worst. The constructor for variable y may be called twice!!!! ------- Disasambly of first example ------- 16: static int i = g (); 00418F58 xor eax,eax 00418F5A mov al,[?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F5F and eax,1 00418F62 test eax,eax 00418F64 jne f+3Fh (00418f7f) 00418F66 mov cl,byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)] 00418F6C or cl,1 00418F6F mov byte ptr [?$S11@?1??f@@YAXXZ@4EA (00438e7c)],cl 00418F75 call @ILT+0(g) (00401005) 00418F7A mov [i (00438e78)],eax 00418F7F ... --- The rest of function code ---
-
Now, I admit I hardly come here anymore, so maybe the rules have changed, but this is not a programming question, the guy is trying to *discuss* something he has *discovered*. How is that wrong for the lounge of a programming site ? Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
Christian Graus wrote: Now, I admit I hardly come here anymore, so maybe the rules have changed, but this is not a programming question, the guy is trying to *discuss* something he has *discovered*. How is that wrong for the lounge of a programming site ? Long time no see CG, I think some of the regulars get a little razzled when they see *any* code at all posted in the Lounge. ;) -Nick Parker
-
Think categorically ? Personally, I'd have thought some discussion on the topic and the suggestion that the guy write an article if it's not already covered somewhere would have been more helpful. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
-
Sorry, forgot to give him is medication last night :rolleyes: The tigress is here :-D
Oh Noooooooooooo!!!!!!!!!!! Regards, Brian Dela :-)