Re: Good practice for an approximation algorithm with start & stop features
From: TT (Tom Tempelaere) (_N_0SPA|/\|titi_____at_hotmail.com|/\|APS0_N_)
Date: 04/02/04
- Next message: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Previous message: Asha: "blocking call for receive"
- In reply to: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Next in thread: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Reply: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 2 Apr 2004 06:01:09 -0800
Hi Jon,
I do not wish to reopen this discussion. But I was just browsing through IDesign's C# coding standard (v1.81) <http://www.idesign.net/idesign/download/IDesign%20CSharp%20Coding%20Standard.zip> and read the following guideline 4.4.19 (p20):
"Do not use volatile variables, ..."
Notice that Juval doesn't write "Avoid ...". He should probably have said "Avoid".
Tom.
----- Jon Skeet [C# MVP] wrote: -----
TT (Tom Tempelaere) <"=?Utf-8?B?VFQgKFRvbSBUZW1wZWxhZXJlKQ==?=" <_N_
0SPA|/\|titi____@hotmail.com|/\|APS0_N_>> wrote:
> What you say is true, and I agree with you. Perhaps I'm still
> struggling too much with my c++ background. But I will have to take
> extra care not to mix the C# volatile with volatile in C/C++ when I
> have to do another project in C++. But that is part of the job I
> guess. I have to constantly be aware of these issues, because I'm
> dealing with different languages all the time. Another fact is that a
> lot of C# coders have a C++ background, and it is worth mentioning
> the difference of volatile in these languages because the languages look
> similar. That's why I mentioned it.
Right. However, treating *anything* as the same between two languages
is a potential problem. That's why I rigorously try to stick with the
idioms, naming conventions etc of a new language - it helps me to think
in that language, rather than one which happens to look like it :)
> I do (of course) hide any specifics of the event to the client, so
> that is not an issue. Asking the thread to finish is just calling a
> method, checking whether shutdown was requested is just another. Then
> one can implement it like he wants.
>> The event stopRunning or the bool stopRunning would have the same
> name. I agree that testing a boolean is more readable than waiting.
Right.
> When you speak of locking, you mean that you would use a locking
> object to access the boolean instead of making it volatile? Like:
>> Object lockObject = new Object();
> bool stopRunning = false;
>> // signal:
> lock( lockObject ) { stopRunning= true; }
>> // check signal
> lock( lockObject ) { if(stopRunning) {...}}
>> Or did I get you wrong?
Nope, that's exactly it. I'd put the actual lock within the property,
but yes, that's the thing. The semantics of "lock" include a read
memory barrier when acquiring, and a write memory barrier when
releasing, so that you get volatile behaviour.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
- Next message: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Previous message: Asha: "blocking call for receive"
- In reply to: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Next in thread: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Reply: Jon Skeet [C# MVP]: "Re: Good practice for an approximation algorithm with start & stop features"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|