Click here to Skip to main content
15,889,825 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: Microsoft "help" Pin
Jwalant Natvarlal Soneji13-Mar-12 18:03
Jwalant Natvarlal Soneji13-Mar-12 18:03 
GeneralRe: Microsoft "help" PinPopular
Reelix14-Mar-12 1:14
Reelix14-Mar-12 1:14 
GeneralRe: Microsoft "help" Pin
Lutosław15-Mar-12 11:49
Lutosław15-Mar-12 11:49 
GeneralUnsafe locking Pin
Member 20530061-Mar-12 5:02
Member 20530061-Mar-12 5:02 
GeneralRe: Unsafe locking Pin
PIEBALDconsult1-Mar-12 6:00
mvePIEBALDconsult1-Mar-12 6:00 
GeneralRe: Unsafe locking Pin
Robert Rohde1-Mar-12 9:36
Robert Rohde1-Mar-12 9:36 
GeneralRe: Unsafe locking Pin
CDP18026-Mar-12 20:48
CDP18026-Mar-12 20:48 
GeneralRe: Unsafe locking PinPopular
CDP18026-Mar-12 21:08
CDP18026-Mar-12 21:08 
Your last version is the simplest and probably the best. Conditional locking with the help of a boolean parameter would only introduce an external source of bugs while (probably) bringing only unnoticably more performance.

What you really should take a look at is the 'Lots of (ahem, good) code here' part. Holding a lock for a longer time may reduce the benefits of working with several threads to zero. You may end up with the performance of a single threaded application. Breaking up the code, identifying smaller critical sections and using several short locks in those locations may help a lot.

I have worked on my own UI. There is an application thread, which of course often makes changes to the controls or their properties, and there is a rendering thread to draw the UI. Not synchronizing those two threads leads to ugly graphical effects when the rendering thread catches the application thread in the middle of some changes. Now I could simply lock the entire control tree when rendering or when making changes to the UI. This would work, but one thread would come to a complete halt when the other one is doing something.

Instead, I never lock the entire tree, but only the one control that is currently going to be rendered or changed. One huge lock has been replaced by many brief locks. This way the two threads collide far less often (only when they happen to access the same control) and if they do, then the wait for the other thread is only brief. Locking is always a manner of 'as much as needed and as little as possible'.
I'm invincible, I can't be vinced



GeneralMy vote of 5 Pin
Julien Villers7-Mar-12 0:05
professionalJulien Villers7-Mar-12 0:05 
GeneralRe: My vote of 5 Pin
greldak12-Mar-12 23:42
greldak12-Mar-12 23:42 
GeneralThousands of links using... PinPopular
krumia29-Feb-12 23:51
krumia29-Feb-12 23:51 
JokeRe: Thousands of links using... PinPopular
ZurdoDev1-Mar-12 5:58
professionalZurdoDev1-Mar-12 5:58 
GeneralRe: Thousands of links using... PinPopular
RobCroll2-Mar-12 12:53
RobCroll2-Mar-12 12:53 
GeneralRe: Thousands of links using... Pin
krumia4-Mar-12 16:35
krumia4-Mar-12 16:35 
GeneralRe: Thousands of links using... Pin
Mohibur Rashid7-Mar-12 22:47
professionalMohibur Rashid7-Mar-12 22:47 
GeneralClassic literature still relevant Pin
MClancy28-Feb-12 4:06
MClancy28-Feb-12 4:06 
GeneralRe: Classic literature still relevant Pin
PIEBALDconsult28-Feb-12 6:00
mvePIEBALDconsult28-Feb-12 6:00 
GeneralRe: Classic literature still relevant Pin
KP Lee13-Mar-12 13:17
KP Lee13-Mar-12 13:17 
GeneralRe: Classic literature still relevant Pin
SASS_Shooter1-May-12 6:29
SASS_Shooter1-May-12 6:29 
JokeFormat string to string Pin
RobCroll27-Feb-12 19:04
RobCroll27-Feb-12 19:04 
GeneralRe: Format string to string Pin
Gary Wheeler28-Feb-12 0:27
Gary Wheeler28-Feb-12 0:27 
GeneralRe: Format string to string Pin
Julien Villers7-Mar-12 0:09
professionalJulien Villers7-Mar-12 0:09 
GeneralRe: Format string to string Pin
scotchfaster16-Mar-12 17:58
scotchfaster16-Mar-12 17:58 
GeneralSilly SQL PinPopular
ZurdoDev27-Feb-12 8:06
professionalZurdoDev27-Feb-12 8:06 
GeneralRe: Silly SQL Pin
Mohibur Rashid27-Feb-12 20:05
professionalMohibur Rashid27-Feb-12 20:05 

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.