Archive for August, 2007

Global Variables are Bad (Usually)

Tuesday, August 14th, 2007

I’m working on an embedded software product that decodes network video and renders it to a monitor.  The application is designed to run 24×7, with up to four streams running through it at a time.  I didn’t write all the code from scratch, I took it over from someone else and am now responsible for bug fixes as well as advancing the functionality. When I inherited the project, I also inherited a bug that was caused by a global variable.  I had made almost a dozen releases with this bug, but it never manifested itself.

The global variable was a wrapper written around the sem_t that handled all of the initialization, destruction, etc.  Someone went into an old C style source file and threw a global instance of that class to provide multi-threaded support.  That might seem fine and dandy, but when unloading the library from memory, a race condition existed that wasn’t very obvious.  Some functions needed to be called in the library during cleanup that relied on the semaphore.  As long as that code was able to execute before the global variable was destroyed, everything worked fine.

The problem is, you have no guarantee of the destruction order of objects.  So, after a bunch of problem free releases, some subtle change had caused the semaphore to be destroyed before the library finished cleaning up.  The application would crash then once the library started to clean up.

I enabled core files and it became pretty obvious that the problem had to do with the semaphore.  It wasn’t the most disgusting global variable problem one might encounter.  I’m just so surprised that people continue to use globals so freely.  I’m positive whoever put that in there did it because it was quick and easy.

There’s no reason that this C file couldn’t have been turned into a class.  It would have only taken a few minutes.  If this person felt that the sem_t was really needed globally to these functions, they could have used some quick regular expressions to make the proper conversions.

So, when is it okay to use a global variable? Almost never.  I can’t give you an example off the top of my head because it’s almost never appropriate.  If you can think of a good example, post it as a comment.

RIAA Out Of Control (Again)

Monday, August 6th, 2007

So the RIAA has gone after Yuri Shutovsky for copyright infringement.  Our good friend Yuri (no, I don’t really know him) has an alibi during the time that this alledged copyright violation occured.  It seems that he was on an extended trip to Russia.   He even offered up his passport showing that he has entry and exit stamps proving that he was in Russia during this time.

Not to be deterred by such trivial details, the RIAA has asked a judge that Yuri turn over all hard drives in his possession as well as the names and addresses of everyone who has ever used his computer.  Unsuprisingly, the judge has sided with the RIAA and has required that he turn over all of this information.  They even asked (very politely, I’m sure) that his work place be required to turn over all information about any computer that he has ever used while in their employ.

Even though Mr. Shutovsky was in Russia during the time of the alledged violation the RIAA believes that  “regardless of who was using the PC at the time, Yuri Shutovsky is responsible for whatever copyright infringement may have occurred by virtue of his paying for broadband from Verizon” (Arstechnica).  By that very argument, Verizon is also responsible for whatever copyright infringement occured because they allowed someone to commit copyright infringement through their network.

But, we all know that RIAA would never go after Verizon.  Why? Because Verizon has enough money that they can afford to hire attorneys competent enough to defend themselves against such a baseless lawsuit.

Here’s a tip to all you record labels out there.  Quit trying to scare your customers into you buying your product.  I know that downloading pirated music is illegal and I honestly don’t understand why people choose to do so.  I can’t understand it because I can’t understand why most people would want to listen to the crap that you sell.  Instead, focus your time, energy, and money on finding and promoting music that is worth buying.  Once you do that, learn to charge a reasonable fee and guess what? People WILL pay for your music.

Scaring your “customers” into paying for your service reminds me an awful lot of the racketeering performed by the Mafia.  In fact, maybe Mr. Shutovsky should sue the RIAA for racketeering?  I’d love to see that civil suit.