Click here to Skip to main content
15,896,201 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: What did he want to lock? Pin
Stanciu Vlad9-Jun-10 3:17
Stanciu Vlad9-Jun-10 3:17 
GeneralRe: What did he want to lock? Pin
Jeroen De Dauw9-Jun-10 4:56
Jeroen De Dauw9-Jun-10 4:56 
GeneralRe: What did he want to lock? Pin
Andrew Rissing9-Jun-10 4:12
Andrew Rissing9-Jun-10 4:12 
GeneralRe: What did he want to lock? Pin
NavnathKale9-Jun-10 8:24
NavnathKale9-Jun-10 8:24 
GeneralRe: What did he want to lock? Pin
David Skelly9-Jun-10 22:37
David Skelly9-Jun-10 22:37 
GeneralRe: What did he want to lock? Pin
Daniel Grunwald10-Jun-10 6:58
Daniel Grunwald10-Jun-10 6:58 
GeneralRe: What did he want to lock? Pin
supercat910-Jun-10 8:52
supercat910-Jun-10 8:52 
GeneralRe: What did he want to lock? Pin
Gary R. Wheeler13-Jun-10 11:41
Gary R. Wheeler13-Jun-10 11:41 
supercat9 wrote:
if a lock must be held between calls to an objects methods or properties, it must be publicly available.


That isn't quite true. An instance member marked private can be the lock value, manipulated solely by members of the class, like this:
class ThreadedWhatsit
{
  public ThreadedWhatsit
  {
    lock(_Lock)
    {
      // do stuff
    }
  }
 
  public ThingType PropertyA
  {
    set
    {
      lock(_Lock)
      {
        _PropertyA = value;
      }
    }
    get
    {
      ThingType propertyA;
      lock(_Lock)
      {
        propertyA = _PropertyA;
      }
    }
  }
 
  private ThingType _PropertyA = new ThingType();
 
  private object _Lock = new object();
}

Software Zen: delete this;
Fold With Us![^]

GeneralRe: What did he want to lock? Pin
supercat914-Jun-10 6:08
supercat914-Jun-10 6:08 
GeneralRe: What did he want to lock? Pin
Gary R. Wheeler14-Jun-10 13:51
Gary R. Wheeler14-Jun-10 13:51 
GeneralRe: What did he want to lock? Pin
supercat915-Jun-10 5:47
supercat915-Jun-10 5:47 
GeneralRe: What did he want to lock? Pin
peterchen10-Jun-10 3:26
peterchen10-Jun-10 3:26 
GeneralRe: What did he want to lock? Pin
bougiefever14-Jun-10 11:19
bougiefever14-Jun-10 11:19 
GeneralFML, Edition 6580 Pin
Wes Jones8-Jun-10 13:56
Wes Jones8-Jun-10 13:56 
GeneralRe: FML, Edition 6580 Pin
Luc Pattyn8-Jun-10 14:33
sitebuilderLuc Pattyn8-Jun-10 14:33 
GeneralRe: FML, Edition 6580 Pin
Wes Jones8-Jun-10 14:58
Wes Jones8-Jun-10 14:58 
GeneralRe: FML, Edition 6580 Pin
Jeroen De Dauw8-Jun-10 19:49
Jeroen De Dauw8-Jun-10 19:49 
Generaluseless... Pin
Noman Aftab6-Jun-10 21:53
Noman Aftab6-Jun-10 21:53 
GeneralRe: useless... Pin
Jeroen De Dauw6-Jun-10 22:55
Jeroen De Dauw6-Jun-10 22:55 
GeneralRe: useless... Pin
J4amieC6-Jun-10 23:44
J4amieC6-Jun-10 23:44 
GeneralRe: useless... Pin
supercat97-Jun-10 6:08
supercat97-Jun-10 6:08 
GeneralRe: useless... Pin
J4amieC7-Jun-10 6:31
J4amieC7-Jun-10 6:31 
GeneralRe: useless... Pin
supercat97-Jun-10 8:52
supercat97-Jun-10 8:52 
GeneralRe: useless... Pin
PIEBALDconsult8-Jun-10 3:21
mvePIEBALDconsult8-Jun-10 3:21 
GeneralRe: useless... Pin
Hired Mind13-Jul-10 10:23
Hired Mind13-Jul-10 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.