Monday, April 6, 2009

Retry Oriented Thread Synchronization

Somewhat recently at work I've been troubleshooting some concurrency edge cases involving deadlocks due to thread synchronization. In my experience, a lot of times this is the result of creating lock objects for separate collections or something of the sort. In most of the code only one collection/object is accessed at a time and the separate synchronization objects allow for less contention and more throughput. Excluding simple/obvious mistakes, the problem typically arises when different code paths require the objects in opposite order, sometimes becoming more difficult to trace when they involve events/handlers. Obviously on goal when locking is to lock the synchronization object for as little time as possible, but sometimes it's simply necessary to hold a lock while entering an event or callback.

One solution, which worked fine for us, was to get rid of one of the synchronization objects and use the same one for both collections. Ultimately it was all that was necessary for our solution, since we couldn't change the other code paths or unlock one of the synchronization roots, but it did inspire me to start trying to think of a better solution. I've been toying with an idea somewhat similar to the pattern used by TransactionScope, taking advantage of the using statement to allow syntax to stay simple (since the lock statement is so lightweight it would be ideal to keep the new solution quick and easy). I certainly haven't found the ideal solution just yet, and it's quite likely that there really is no ideal solution, but I've posted the new code and test application on CodePlex, hoping others in the community will see the potential advantages and help me improve on it, either with code or ideas. This also doesn't implement any synchronization techniques regarding Mutexes, Semaphores, or any other wait handle style synchronization, this is currently specific to using Monitor and may only serve to improve circumstances using traditional lock statements or Monitor directly.

The general concept behind usage in the current implementation is as follows:

using (LoopLock l = new LoopLock(ltp.Syncs))
{
//optional event, but here for testing
l.LockAttemptFailed += new LoopLockEventHandler(delegate(LoopLock sender, LoopLockEventArgs e)
{
if (e.Attempts > 200)
{
//sample of aborting if it takes to long to get a successful lock;
e.AbortLock();
}
});

l.AcquireLock();

Thread.Sleep(rnd.Next(5490) + 20);

}
The LoopLock constructor takes in a params array of all the synchronization objects (in the order they should be locked). The AcquireLock method only exists to allow attaching an event handler, which will be described in a moment. AcquireLock attempts to obtain a lock on each synchronization object one at a time. If it is unable to obtain any lock in 100ms (by default, though there is a constructor overload to provide the timeout period) it will proceed to unlock each of the successfully locked objects (in reverse order), fire the LockAttemptFailed event which provides the number of tries so far along with the option of aborting the process alltogether (which throws a LoopLockAbortedException). If all locks are acquired code will proceed and, when the code leaves the scope of the using statement, all locks are released (in the opposite order they were locked).

One thing I've already considered through the simple test application I've made is the possibility of adding support for prioritization based on retry counts, which could be useful, but since these are thread specific and this is supposed to be a lightweight class it may require the use of WeakReferences so I haven't gone through with it yet since I'm still working on finding other possibilities and it could wind up being a waste of effort. One problem mentioned above that this still doesn't solve is the event handler situation, where I lock a synchronization object important to me and then fire an event which can be attached to by arbitrary code; since I don't have control over both code-bases I can't see a means to provide any "let me get out of your way" logic, since we can't release the lock once synchronization-dependent code has already begun executing. I was thinking about the possibility of a delegate or delegate wrapper that carries a reference to the synchronization object would work for some occasions, but without some under-.NET's-hood voodoo it would still sacrifice syntax clarity/diversity, which I'm trying to avoid. It seems there will have to be a tradeoff somewhere in order to improve this model, and maybe using a single callback with a synchronization object reference instead of supporting a multicast delegate may be that answer, but for now I'm going to think on it more. I would really love any insight from those in the wilderness; I've certainly not been exposed to every method of using threads and synchronization and, while I'm pretty familiar with Monitor and other synchronization classes, there could still be something obvious I'm not privy too as well.

-TheXenocide

Saturday, January 10, 2009

Selective Interpretation

Well, I haven't posted in forever, and this isn't what I was shooting for, but I went on another rant in some forums related to "The Boondocks" animated TV series so I figured I'd post it here. Fragile readers beware, this is a serious and potentially controversial topic. You don't have to agree with me, but this is my little brain dump and I'd like to let others read it. If you have a sufficient argument (with some intellect behind it) feel free to debate, but here goes:

Anybody who sets or adheres to a policy that one race can do something and another can't (like say "the n word") is a racist.

I don't consider it important to mention what "color" or "race" I am, but suffice it to say that I've lived (throughout several states) in "the projects", inner city, suburbs, "redneck" country, been homeless, lived in a 3 bedroom house on an estate by the water and more. In the projects and city I said "the n word" and was called "the n word" on a daily basis and it didn't mean a thing until I moved somewhere else and experienced people selectively interpreting the term as offensive. I've seen different "rules" about who can and can't say it in every different place I've lived (even ones like "n*gga" is different from "n*gger" and places that say Latinos and South Americans are qualified; did you know the English have used it to refer to the Irish?). I understand full well the history and the connotation of the word, but as it stands today it's not about the word, it's about the intention.

If someone wants to be offensive it doesn't matter what words they use, they're going to be perceived as offensive. If someone wants to be offended, it doesn't matter what the circumstance is, they will find something to be offended about. Some people strive for drama (like people who react every time a non-"black" *person* says it) and some people are afraid of it (like people who aren't racist but are afraid to say the word because they figure people will think they are) but, ultimately, all of these responses are just giving power to something that is nothing more than a word. If I say sh*t or f**k today most people will just think it's normal or maybe somewhat irresponsible, but there was a point in time when it was very offensive (the term "curse words" comes from the idea that people would literally be cursed for using them; clearly they weren't and people realized it and moved on). What changed? The words didn't; only the mentality did. Just the same, people also say "bless you" because at some point people thought that sneezing expelled the soul from the body and that "blessing someone" would somehow put it back in or protect them.

We set the standards by living them, so you can support racism by taking a racist stance (like one person can say something that another can't) or you can move on and live your life like nobody is different which will (even if only slowly) change the general mentality and (hopefully) abolish racism/sexism/*ism. Remember that freedom is the right to do whatever you want so long as you don't affect someone else's right to do what they want.

We learn new things every day and the thing that holds us back more than anything are the people who refuse to move forward. Grow up, help mankind, and get over yourself and the past to work for a better future. Cracker, Wap, Porch-Monkey (somebody! quick! take it back! ;p), Spic, whatever: it doesn't matter unless you let it. We can't change the past; no word will ever be eliminated, sometimes most people just stop using it. Then again I'm being a bit loquacious, which is a word that is hardly ever used today (though I did wind up using it the other day), but it's still available when someone (like myself) wants it.

Who's to say any culture is "ours" or "yours" or anyone else's for that matter?! Ethnicity isn't about race (scroll down); it's about shared experiences and learning, much more frequently associated with location and is sometimes associated with a minority group, but only in a more recent and selective definition which also requires you to interpret religion in the same boat (anybody have any preconceptions about Muslims?). People appreciate and learn new cultures; the people that made Adult Swim what it is were appreciating Japanese culture and then it slowly became that of the "nerd" which the majority of were smart enough to appreciate anything made with some sort of intellect and humor (like "The Boondocks"). In any given week I eat food from at least 5 different cultures, including the "American" culture which has basically been a very recently evolved combination of many other cultures. Ultimately there are people who are trying to pretend they're something they're not so that people will see them a certain way ("cool" perhaps?) which, no matter whether it be "black" culture or the "popular" clique, always stand out as idiots who aren't confident or happy enough with themselves to be real. Anybody that makes "exceptions" to these racist institutions does so on the basis that someone is being "real" as opposed to being a "poser." You can pretend they're all different situations if you want, but you're selectively interpreting things to make your own life easier so you don't have to learn and evolve your own perspective. People want everyone else to see the world the way they do (subjectively) instead of trying to look at the world objectively and learning about their own inaccuracy. "Black" "Hip-hop culture" isn't even remotely close to what it was 10 years ago, let alone like the "black culture" of slavery or Jim-Crow-era post-slavery; cultures grow and evolve as people interact and move from one to another. Check the British Lady Sovereign et al on "The Battle" and you'll catch a completely different infusion of cultures made by people of multiple "races" - it doesn't matter what color they are or where they're from. Once you get past the accent you have to admit they spit real fire.

I'm seriously concerned about how many people look at this topic without ever taking a step back and looking at the big picture. With any luck the world will now be a better place; thanks for your time if you made it through all this.

Be real (Aaron McGruder would be),

-TheXenocide

Thursday, October 30, 2008

Wasting Time Explaining a Waste of Time

The views expressed here forth are a response to an article posted on American Thinker and assuming, like the many comments already visible therein, that it is not rejected during moderation, this will also be viewable there.

Let it be known, first and foremost, that I do not believe either party candidate to be of any *real* value to the citizens of this country. That said, this entire "controversy" is a waste of time; the prerequisites for presidential candidacy are checked in most states, if not all. Additionally, many US citizens maintain citizenship in other countries that do not provide for Dual Citizenship and the United States has not overturned their citizenship. I know people who *work for the US government* that maintain citizenship in Italy, Japan and Egypt personally and, while their citizenship in those countries is not recognized while they're in the United States (meaning they can not seek harbor in an embassy to require extradition for prosecution), this has not nullified their citizenship (in fact the US *only* recognizes their US citizenship). Also, once you are a natural born US citizen the citizenship status or changes of your parents does not affect your own unless it can be proven that they never were US citizens in the first place. Simply put, citizenship gives the US legal system more capability and, as such, they use it whenever convenient. Even if Obama *had* shown a birth certificate to an unfriendly source in person we would still be depending on the words of someone else rather than deciding for ourselves; is it now the responsibility of every political candidate to carry their birth certificate on their person so as to show it to everyone? What happens if/when it gets stolen? I know I don't carry mine with me just to prove I'm a citizen, I just show it to the appropriate government office when they require it and put it back in a safe place.

Additionally, Obama's health records, while not complete and detailed, or no less reliable than the exposure McCain has provided (effectively very limited access by few people for a limited time) and the analysis of these limited views still show Obama to be in significantly higher health. If you're going to require health records, which I completely agree with, require complete disclosure from all candidates.

Molotov also makes bold claims when stating that they released information before "anybody knew," clearly showing exaggeration since they obviously weren't part of the movement and likely had to take their information from somebody. Also, conspiracy is defined as "an evil, unlawful, treacherous, or surreptitious plan formulated in secret by two or more persons" amongst other similar derivatives, which this video is (not that I mind, it's important to consider the possibilities of these things, the term has been loaded with a negative "foil hat" image), keeping in mind that a search for "Illuminati" will return results almost entirely consisting of conspiracy theories.

This article serves as nothing more than smoke-screen in an ever-filled political atmosphere through which too many people are depending on the unproven words of "smart people" instead of looking the information up and deciding for themselves. If this is supposed to be published for an "American Thinker" why not *think* before disseminating it?

P.S. McCain has a similar case brought up and, rightly so, both have been dismissed on similar terms. I suppose its only fair to question the citizenship of every candidate, but don't you think the process would have booted them by now?

Friday, September 26, 2008

Longwinded Response and Declaration of Political Views

I've been working on the majority of this for quite some time and was about to paste it in a forum discussion (found here) until I realized that it's even longer than my usual rants (I guess that's what happens when I let it build over time ;p). Some of the segments/content herein are new or altered and serve primarily as response to posts in the forum.

It seems we have similar views, but I find it hard to believe that a constitutionalist (like myself) would vote for McCain simply based on his Senate record. Ron Paul was the most constitutionally aligned candidate this election, but bad press and primary campaign funding coming from the grassroots internet movement didn't put him far enough forward for people to research his platform enough to understand his position. My opinion about America and it's core values seems, to me, to be common sense from middle school social studies class, but it may be that many Americans have become too lazy or their perspective is outside the scope of my understanding. I agree with you on a lot of the points you make, but I don't think that you've actually given any particularly good reasons for your position. I also believe that more people should acknowledge just how much George W. Bush has hurt our constitutional rights; this is very important because John McCain has voted 90+% along with Bush over several years while he and his confused VP receive support from bigoted leaders without addressing the awful things they say. It's also incredibly important that the American people not be convinced to let up on their prying; these people will become the most powerful people in the world. It's massively important that we let resolution come (the opposite of postponing) to things like the next troopergate investigation before making decision about a woman who could very easily become a replacement president with an unadressed reasonable statistical possibility of natural death.

I feel that the absolute most important principle in American values is freedom. I define freedom as the right to do whatever you want so long as you do not get in the way of anybody else doing what they want. I believe that in America, the only purpose of law is to protect our freedoms. Murder, rape, theft, discrimination, etc. are matter-of-factly an aggression against the freedom of another citizen. With that said, I think that voting for a candidate (who isn't even running for part of the legislative branch, mind you) based on their opinions about concepts that we can not, based entirely on fact, say is an attack on the freedom of another should not even touch the floor of congress, let alone be part of a candidate's platform. The tiered/federalized system supports the possibility of like-minded people grouping and enforcing common opinion; the federal governments primary purpose is to protect our constitutional liberties. We do, however, have quite a mess on our hands given the state of the economy.

Income tax is entirely unconstitutional as the 16th amendment was never properly ratified and it is neither a direct apportioned tax, nor an indirect uniform tax (this interview does a fine job explaining the position) and is therefore not even remotely close to an executive branch concern so much as legislative and/or judicial. It is also against our founding principles due to the fact that it enforces taxation in Washington D.C. and other unrepresetned zones (taxation without representation, anybody?). The same branch-orientation applies to abortion as the only thing a president can do is appoint justices and choose to veto or not, which congress can, on our behalf, override in a true majority based decision anyway (overriding veto with process or judicial review with new legislation/ammendments). We should be looking for a president that knows these things well, as it will be his job, and acts accordingly. We don't need a President who is pro-choice or pro-life, we don't need a President who will legalize drugs (as much as I believe drug related infractions should be based on what laws they've broken that affect other people, like killing someone while driving intoxicated, not based on what you decided to put in your body while sitting in the comfort of your living room) since he can't legalize/decriminalize anything.

What we truly need is a President who knows to Veto a bill that does not benefit the majority of our population, such as the Patriot Act which was written before the event utilized to pass it and which passed without elected officials even reading it. We need a president that doesn't "authorize" warrantless wire-types on US citizens without reason. We need a President that knows that passing a law that gives the President the ability to declare martial law is the opposite of supporting our constitution's foundation (too late again, of course). We need a President that isn't going to lie to us to support his own agenda or cover his friends' a**es or to establish fake enemies with no proof which degrade society by supporting race/religious hate and enforce an international stereotype of the mean and stupid nature of Americans.

Unfortunately, over the last century we've dug ourselves into such a deep hole of non-majority supporting legislation that, at this point, we need government involvement just to clean up after the mess we let our government make in the first place, but far more importantly we need Americans that hold their representation accountable and force action even when our politicians turn into flopping fish because of their campaign funding or other misrepresentation rationalizations. We need Americans that are willing to push their representation for impeachment when their position has been misused, rather than over suits that with little impact on America that can be handled in civil courts.

The privatized fiat currency we've allowed to gradually destroy our economy while being convinced (for whatever reason I do not know) that printing more of it can actually fix something is a mess that can't be resolved in one term. The money we waste declaring war on our own people (War on Drugs) sending armed forces into the homes of families near "farmers" in California (this used to be illegal), or arresting large numbers of people in unfortunate circumstances negatively affecting one or two people, all the while bailing out white collar criminals who have potentially contributed to the destruction of the lives of millions (criminals punished by paying them millions of dollars for failing to perform their duties effectively). This isn't something that can be fixed without the government, it's something the government needs to fix on our behalf.

Lastly, while battleground states can be very narrow lines, the only reason that it is currently "impossible" to elect a candidate outside the two major parties is that everybody seems to think that they have to vote one or the other or they're throwing their vote away. This isn't actually a two-party country, there's just an illusion that benefits big business and continuity of current tactics. The person who wins is the person with the most electoral college votes, no questions asked, period. Still, regardless of differences of opinion I'm very happy to see that many of us are still actively engaging in discussion and debate about these concerns. It gives me hope, and it's the only thing we can use to change these dangerous illusions.

Thursday, September 18, 2008

White Privelege

I didn't write this, and I didn't find it, a friend of mine by the name Chris Scott posted someone else's work and I was very impressed with it. Sorry, I know I haven't written anything myself in some time and I need to get back on that, but for now, taste a bit of this:

September 13, 2008
This is Your Nation on White Privilege
By Tim Wise


For those who still can't grasp the concept of white privilege, or who are looking for some easy-to-understand examples of it, perhaps this list will help.

White privilege is when you can get pregnant at seventeen like Bristol Palin and everyone is quick to insist that your life and that of your family is a personal matter, and that no one has a right to judge you or your parents, because 'every family has challenges,' even as black and
Latino families with similar 'challenges' are regularly typified as irresponsible, pathological and
arbiters of social decay.

White privilege is when you can call yourself a 'fuckin' redneck,' like Bristol Palin's boyfriend does, and talk about how if anyone messes with you, you'll 'kick their fuckin' ass,' and talk about how you like to 'shoot shit' for fun, and still be viewed as a responsible, all-American boy (and a great son-in-law to be) rather than a thug.

White privilege is when you can attend four different colleges in six years like Sarah Palin did (one of which you basically failed out of, then returned to after making up some coursework at a community college), and no one questions your intelligence or commitment to achievement,
whereas a person of color who did this would be viewed as unfit for college, and probably someone who only got in in the first place because of affirmative action.

White privilege is when you can claim that being mayor of a town smaller than most medium-sized colleges, and then Governor of a state with about the same number of people as
the lower fifth of the island of Manhattan, makes you ready to potentially be president, and people don't all piss on themselves with laughter, while being a black U.S. Senator, two-term state Senator, and constitutional law scholar, means you're 'untested.'

White privilege is being able to say that you support the words 'under God' in the pledge of allegiance because 'if it was good enough for the founding fathers, it's good enough for me,' and not be immediately disqualified from holding office--since, after all, the pledge was written in the late 1800s and the 'under God' part wasn't added until the 1950s--while believing that reading accused criminals and terrorists their rights (because, ya know, the Constitution,
which you used to teach at a prestigious law school requires it), is a dangerous and silly idea only supported by mushy liberals.

White privilege is being able to be a gun enthusiast and not make people immediately scared of you.

White privilege is being able to have a husband who was a member of an extremist political party that wants your state
to secede from the Union, and whose motto is 'Alaska
first,' and no one questions your patriotism or that of
your family, while if you're black and your spouse
merely fails to come to a 9/11 memorial so she can be home
with her kids on the first day of school, people immediately
think she's being disrespectful.
White privilege is being able to make fun of community
organizers and the work they do--like, among other things,
fight for the right of women to vote, or for civil rights,
or the 8-hour workday, or an end to child labor--and people
think you're being pithy and tough, but if you merely
question the experience of a small town mayor and 18-month
governor with no foreign policy expertise beyond a class she
took in college and the fact that she lives close to
Russia--you're somehow being mean, or even sexist.

White privilege is being able to convince white women who
don't even agree with you on any substantive issue to
vote for you and your running mate anyway, because suddenly
your presence on the ticket has inspired confidence in these
same white women, and made them give your party a
'second look.'

White privilege is being able to fire people who didn't
support your political campaigns and not be accused of
abusing your power or being a typical politician who engages
in favoritism, while being black and merely knowing some
folks from the old-line political machines in Chicago means
you must be corrupt.

White privilege is when you can take nearly twenty-four
hours to get to a hospital after beginning to leak amniotic
fluid, and still be viewed as a great mom whose commitment
to her children is unquestionable, and whose 'next door
neighbor' qualities make her ready to be VP, while if
you're a black candidate for president and you let your
children be interviewed for a few seconds on TV, you're
irresponsibly exploiting them.

White privilege is being able to give a 36 minute speech in
which you talk about lipstick and make fun of your opponent,
while laying out no substantive policy positions on any
issue at all, and still manage to be considered a legitimate
candidate, while a black person who gives an hour speech the
week before, in which he lays out specific policy proposals
on several issues, is still criticized for being too vague
about what he would do if elected.

White privilege is being able to attend churches over the
years whose pastors say that people who voted for John Kerry
or merely criticize George W. Bush are going to hell, and
that the U.S. is an explicitly Christian nation and the job
of Christians is to bring Christian theological principles
into government, and who bring in speakers who say the
conflict in the Middle East is God's punishment on Jews
for rejecting Jesus, and everyone can still think you're
just a good church-going Christian, but if you're black
and friends with a black pastor who has noted (as have Colin
Powell and the U.S. Department of Defense) that terrorist
attacks are often the result of U.S. foreign policy and who
talks about the history of racism and its effect on black
people, you're an extremist who probably hates America.

White privilege is not knowing what the Bush Doctrine is
when asked by a reporter, and then people get angry at the
reporter for asking you such a 'trick question,'
while being black and merely refusing to give one-word
answers to the queries of Bill O'Reilly means you're
dodging the question, or trying to seem overly intellectual
and nuanced.

White privilege is being able to go to a prestigious prep
school, then to Yale and then Harvard Business school, and
yet, still be seen as just an average guy (George W. Bush)
while being black, going to a prestigious prep school, then
Occidental College, then Columbia, and then to Harvard Law,
makes you 'uppity,' and a snob who probably looks
down on regular folks.

White privilege is being able to graduate near the bottom
of your college class (McCain), or graduate with a C average
from Yale (W.) and that's OK, and you're cut out to
be president, but if you're black and you graduate near
the top of your class from Harvard Law, you can't be
trusted to make good decisions in office.

White privilege is being able to dump your first wife after she's disfigured in a car crash so you can take up with a multi-millionaire beauty queen (who you go on to call the c-word in public) and still be thought of as a man of strong family values, while if you're black and married for nearly twenty years to the same woman, your family is viewed as un-American and your gestures of affection for each other are called 'terrorist fist bumps.'

White privilege is being able to sing a song about bombing Iran and still be viewed as a sober and rational statesman, with the maturity to be president, while being black and suggesting that the U.S. should speak with other nations, even when we have disagreements with them, makes you 'dangerously naive and immature.'

White privilege is being able to claim your experience as a POW has anything at all to do with your fitness for president, while being black and experiencing racism and an absent father is apparently among the 'lesser adversities' faced by other politicians, as Sarah Palin explained in her convention speech.

And finally, white privilege is the only thing that could possibly allow someone to become president when he has voted with George W. Bush 90 percent of the time, even as unemployment is skyrocketing, people are losing their homes, inflation is rising, and the U.S. is increasingly isolated from world opinion, just because white voters aren't sure about that whole 'change' thing. Ya know, it's just too vague and ill-defined, unlike, say, four more years of the same, which is very concrete and certain.

White privilege is, in short, the problem.