Trump, Ambiguity, and Bias

Posted: August 12th, 2016 | Author: | Filed under: Politics & Policy | No Comments »
I have watched, with considerable fascination, the uproar over certain recent comments by Trump. As is all too common with statements by Trump, people on both sides of the aisles have responded by attacking him, and each other, with passionate rhetoric.

Trump is no stranger to strategic ambiguity; his campaign has practically reveled in it. I’ve lost count how many ideas he has promised to “look into”. This ambiguity serves him well, even if he appears to some as incoherent. He can avoid making promises, while still sending supportive signals to special interests. All politicians do this, of course, but Trump seems unusually willing to go off message for potential supporters.

This statement, and the reactions to it, have been unusually interesting. It is, in my view, an excellent teaching example of how our biases affects our perceptions.

Hillary wants to abolish — essentially abolish — the Second Amendment. If she gets to pick her judges, nothing you can do, folks. Although the Second Amendment people, maybe there is. I don’t know.

Take a moment to consider the inherent ambiguity of the statement. Who does he mean by “Second Amendment people”? What does he mean by implying there is something they can do? These concepts are completely undefined in context. Thus this statement, on its own, can be taken to mean one of many things. Here are a few that I see:

  1. People with guns should assassinate Hillary Clinton
  2. People with guns should overthrow the government
  3. People who care about gun rights should vote for Trump
  4. Gun rights lobbyists could convince Congress to block her SCOTUS appointments

Take another moment to consider your own reaction. What do you believe Trump meant? How passionately do you believe that? What is the evidence for your position? What other interpretations did you consider, if any? What evidence, if any, did you consider for other interpretations? How did you rule out other interpretations as valid hypotheses?

Confirmation Bias

In this fascinating paper , P.C. Wason showed some of the first rigorous experimental evidence for the effect he named confirmation bias.

His experiment was simple. I have a rule that 3 number sequences must obey. Your goal is to guess the rule. I will give you a starting sequence, and you can ask if sequences obey the rule.

Let’s say the starting sequence is: 2, 4, 8. How do you figure out the rule?

The NY Times implemented this game here. Take a minute, and try it yourself. It doesn’t take long.

Confirmation bias has been well studied in the 56 years since Wason’s paper. His paper, Wikipedia, and the Times’ article discuss it better than I can. But this excerpt from Wason sums it up concisely:

Inferences from confirming evidence (Bacon’s “induction by simple enumeration”) can obviously lead to wrong conclusions because different hypotheses may be compatible with the same data. In their crudest form such inferences are apparent in the selection of facts to justify prejudices.

Bias and Interpretation

We form models of varying strength and reliability about every aspect of the world, and use these models to navigate daily life by justifying beliefs about observations whose objective truth is unverifiable. This reasoning is not inherently wrong, so long as the strength of the belief is in line with the strength of the model and the strength of the evidence. However, this reasoning becomes confirmation bias when we elevate our belief to evidence that justifies our belief, while ignoring contrary evidence.

Returning to Trump’s statement, let’s examine the available evidence supporting various interpretations.

  1. People with guns should assassinate Hillary Clinton
    Evidence: Trump has a history of using unusually violent rhetoric in this campaign. However, there was no explicit mention of violence, and Trump has not previously been particularly shy about speaking his mind.
  2. People with guns should overthrow the government
    Evidence: Overthrowing a tyrannical government is a popular “dog whistle” for gun rights supporters. Trump has frequently been accused of using dog-whistle politics. However, accusations of dog-whistles are by nature difficult to prove, and are sometimes themselves dog-whistles.
  3. People who care about gun rights should vote for Trump
    Evidence: The statement’s immediate context was a list of reasons voters should prefer voting for Trump over Hillary. However, Trump is notorious for going “off-message” in rallies. The Trump campaign has officially endorsed this interpretation. However, campaign staffs regularly spin unfortunate comments from their candidates. They, and the candidate, have strong motivations to lie.
  4. Gun rights lobbyists could convince Congress to block her SCOTUS appointments
    Evidence: None, really. I just threw this in here.

Strongly preferring one of these interpretations requires not only justifying the supporting evidence and dismissing the contrary evidence, but also dismissing the evidence for any other interpretation. But with an ambiguous statement in an unreliable context, it’s impossible to know with certainty what was actually meant. The strength of our beliefs here comes from our strong beliefs in our mental models about Trump: it is from drawing on our personal perceptions of Trump, and what we think Trump might say.

If, for example, we use our interpretation that Trump was advocating violence to push the narrative that Trump advocates violence, we must do so at the expense of all other interpretations by turning a belief into a fact, without any further justification than our pre-existing belief. We are selecting facts to justify prejudices.

While expedient and perhaps helpful in achieving short term goals (such as successfully disparaging a deeply disliked candidate in the eyes of others), this comes at a great cost: rationality itself. Rational discourse, while always in short supply, seems to dissipate completely during political campaigns. By refusing to temper our own rhetoric with rationality, we contribute to the fundamental failure of modern politics.

In the end, refusal to confront our biases only drives us further from Truth.

(Personal bias disclaimer: I am pro-gun rights, and I support the right of the people to overthrow tyrannical governments. My initial interpretation of Trump’s statement was interpretation #2.)

3rd Party Voting: Morality and Pragmatism

Posted: August 8th, 2016 | Author: | Filed under: Politics & Policy | No Comments »
There are many voices, on both sides, challenging the moral right and pragmatic wisdom of 3rd party voting. These arguments usually boil down to tribalist lesser evilism, the accusation of wasting votes, and SCOTUS appointments. I think these are wrong, and the thinking behind them is inherently harmful.

Don’t Vote For The Wrong Lizard!

I view trying to guilt me into support an organization or person I don’t believe in as tantamount to telling me that moral values, principles, identity, and beliefs don’t matter, that the only thing that matters is tribal affiliation. But I see increased tribalism as the source of our problems, not the solution. It means that candidates don’t matter, virtue and character don’t matter, policy doesn’t matter, civil liberty doesn’t matter, respect for American civics and the Constitution doesn’t matter — the only thing that really matters is in-group affiliation and out-group fear-mongering. When my choices boil down to an authoritarian nationalist or a kleptocrat, arguments over which is the lesser evil mean nothing when both are an existential risk to the principles of liberal democracy. No, thank you.

Don’t Waste Your Vote

Saying that voting third party doesn’t have any effect is wrong. The cutoff for minor party Federal public funding is 5% of the vote in the previous election. For those of us who are looking for long-term change, that does matter — it matters a lot. Strong third party support, both in votes and in finances, has a chance to force realignment of the major party coalitions that have become unsatisfying to nearly everyone. For this post, I will oversimplify the coalitions as roughly this:

R: Nationalists, Evangelicals, Business Republicans

D: Socialists, True Progressives, Third Way Democrats

(For a richer, more data-driven analysis, see this research by Pew.)

The problem is, in my view, that these alliances are over-strained, and no longer serve strong shared common interests. The Business Republicans and Third Way Democrats, for example, share far more in common than either does with the Nationalists or Socialists they are paired with. The only reason they stay together is because of financial incentives. Cutting off the flow of donations into these coalitions and increasing the fiscal viability of a third party may be exactly the strain we need to bring about new coalitions that more accurately reflect common goals.

Additionally, the wasted vote arguments often ignore the effects of the Electoral College. Mathematically, a huge number of votes cast for a presidential candidate are wasted because of “first past the post”. This article gives a good mathematical breakdown.

But SCOTUS appointments!

This is, perhaps, the most pernicious argument: if the wrong tribe of president is elected, the president will appoint wrong tribe SCOTUS justices, who will make decisions favoring wrong tribe.

This argument is particularly poisonous, because it implicitly advocates for more judicial activism. It suggests the purpose of voting is to select the person who will appoint people to serve as lifetime, unaccountable oligarchs who can create laws and rules for our society at their whim. It is, therefore, advocating the dismantling of our Constitutional republic itself. With apologies to Gerald Ford:

A Supreme Court powerful enough to support all of your causes, is powerful enough to strip you of all your rights.

Fortunately for now, the court has shown much greater unity and restraint than it is often given credit for. As the National Review notes here:

These concerns are not misplaced, but the apocalyptic tone misrepresents the Court’s actual, year-by-year activity. Consider: Between January 2012 and June 2014, the Supreme Court ruled against the Obama administration unanimously 13 times — on everything from recess appointments to abortion-clinic “buffer zones.” This was not an anomaly. Since 1995, almost every year has seen more than 40 percent of cases — that is, a plurality — decided unanimously; in 2013, it was two-thirds. (To be fair, there are different degrees of unanimity.) Meanwhile, only twice since 1995 have more than 30 percent of cases split 5-4.This suggests that the Court’s justices are more likeminded legally than political pundits often recognize.

The only wasted vote is for a vote for a candidate you don’t actually support; the only immoral vote is a vote against your own values.

Vote your conscience. Fight for your values.


Posted: September 16th, 2015 | Author: | Filed under: Politics & Policy | Tags: , , | No Comments »

The story of Ahmed Mohamed and his clock has exploded over the internet today. In case you’ve been hiding under a proverbial rock, here’s the short version: Ahmed built a clock. He brought the clock to school, to show one of his teachers. Panic ensues, through absolutely no fault of his own.

For the record, here is a picture of the clock:

Ahmed's clock

To me, it looks like a circuit board in a protective case. But I’m a computer engineer with a minor in physics, so I’ve seen lots of circuit boards and protective cases.

The problem isn’t that ignorant people were confused at first glance. The problem is that, even after they were completely convinced that it was a clock, and even after they ascertained that there was no evidence of nefarious intent, they still punished the kid for doing absolutely nothing wrong.

Ken White performs an excellent evisceration of the absurd behavior by authority figures towards 14 year old Ahmed.

In his head, Ahmed lives in an idealized world he learned about in robotics club: a world where individuality and curiosity and initiative are appreciated. Or at least he did. But this week he found out that he actually lives in a different world, a grim real world controlled by school administrators and cops who are deeply suspicious of individuality, if not openly hostile.

Just read the statements by the police:

“We have no information that he claimed it was a bomb,” McLellan said. “He kept maintaining it was a clock, but there was no broader explanation. It could reasonably be mistaken as a device if left in a bathroom or under a car. The concern was, what was this thing built for? Do we take him into custody?”

To answer the rhetorical question “Do we take him into custody?”, simply follow this heuristic:

Did he break the law?
Yes –> Yes
No –> No

Yet building a clock requires “broader explanation”, because these school administrators, teachers, and police are simpletons. Their minds are uncomplicated with knowledge or creativity. The idea of challenging oneself intellectually for fun is simply beyond them. It reminds me of a quote from The Hacker’s Manifesto:

“My crime is that of outsmarting you, something that you will never forgive me for.”

However, it goes beyond that. Authorities are perpetually looking for a way to assert their control over us. The inconvenient truth is that we are not usually in any real, imminent danger. With the limited availability of actual threats, authorities look for more and more innocuous actions to punish, reminding us THEY ARE PROTECTING US FROM THREATS AND WE NEED THEM! The fact that he was Muslim (and looks Arab) was simply the excuse they needed — an easy way to prey on prejudice. LOOK! THEY ARE PROTECTING US FROM TERRORISTS!

If there was no prejudice against Muslims, they would suspend 7 year olds for chewing a pop tart into the vague outline of a gun. They would suspend 8 year olds for playing cops & robbers with finger guns. They would suspend 7th graders for twirling pencils. LOOK! THEY ARE PROTECTING US FROM VIOLENCE!

Or, perhaps, they would strip search a 13 year old girl for suspicion of possession of ibuprofen. Maybe they would suspend and prosecute an 11 year old for possessing a Japanese maple leaf. LOOK! THEY ARE PROTECTING US FROM DRUGS!

Of course, this extends to all levels of authority.


The FBI wants to back-door all our encryption. LOOK! THEY ARE PROTECTING US FROM CHILD MOLESTERS!

Local police wants to stop-and-frisk. LOOK! THEY ARE PROTECTING US FROM CRIMINALS!

The DEA bulk collects phone, license plate, and who knows what else data on American citizens, en masse. LOOK! THEY ARE PROTECTING US FROM DRUGS!

I hope Ahmed receives justice from this. I hope he launches a successful STEM career. I also hope he takes to heart the very important lesson, “Authority is not your friend.”

MultiLinks 6-12-2015

Posted: June 12th, 2015 | Author: | Filed under: MultiLinks | No Comments »

What Is Code?

If you don’t understand computer programming or how computers work, this is absolutely the best explanation I have ever seen. It’s accurate, simple, and clear. If you’ve ever wanted to understand computers and computer programming, read this.


The Vagus Nerve: A Back Door for Brain Hacking

I am extremely skeptical of this. Lots of promises, but we’ll see. I’m suspicious that this is going to turn into the next pop-med cure.


High Frequency Trading Model

It’s rare to see an actual, functional algorithm for HFT methodologies. This is a simple example of statistical arbitrage. In the coming weeks, I’m hoping to port this to QuantConnect’s Lean Engine in a few weeks.


Is Russia’s space program in crisis?

So Russia’s program is corrupt and falling apart. Still better than the US, since the US program cannot currently put people into orbit.


Airbus unveils Adeline, its clever answer to SpaceX’s reusable rockets

Speaking of space: Airbus now has a plan to reuse lower stages, and reduce launch costs. Thanks, SpaceX. Unlike the UAL’s insane-sounding mid-air recovery plan, Airbus’ plan actually sounds like it might work.

Swift has had a successful year

Posted: June 12th, 2015 | Author: | Filed under: Programming | Tags: , | No Comments »

As expected, Swift’s adoption is picking up quickly. It’s a nice language, with the modern look and feel that defines current languages:

  • Simplified method declarations
  • No semicolons on end of line
  • Functions as first class citizens
  • Lambdas
  • Some sort of memory management (ARC in Swift’s case)
  • Implicit typing
  • Etc.

It’s going through growing pains, as the language spec and tools are still immature. However, it’s a language with all the buzzwords and behaviors programmers currently want. Plus, if Apple follows through with it’s plan to open source Swift 2.0, a major hurdle to adapting Swift on other platforms will be removed.

As far as general non-Apple programming goes, Swift has some serious competition for mindshare in Google’s Go and Mozilla’s Rust. Go has a serious head start, and is solving real problems at Google and everywhere else these days; unfortunately, Google has a bad habit of abandoning projects. Rust looks like an absolutely amazing language, and I think it is the best-designed of the three (better type system than Go, better memory management than Swift). I’ll be curious to see if anyone actually uses it.

Swift, on the other hand, is Apple’s “language of the future.” Apple and Swift are in a similar position to Microsoft and C#. With a large development community eager to/forced to lap up whatever Apple brings down the pipe, I suspect Swift will continue to gain popularity.

MultiLinks 6-5-2015

Posted: June 5th, 2015 | Author: | Filed under: MultiLinks | No Comments »

Intel will acquire FPGA maker Altera for $16.7 billion
Whoa. This is a huge deal. I’ll be very interested in seeing what Intel does with this.

Kubernetes – The Future of Deployment
This is an incredible technology. While Docker has slowly tried to add orchestration features like Machine, Swarm, and Compose, they are still somewhat immature and don’t fully work together well. You can read more about Kubernetes here and here. This is still immature and ambitious, but with Google’s experience behind it, I think it will develop quickly — assuming they don’t get bored. 😉

Majority of websites have serious, unfixed vulnerabilities
I’m shocked, shocked I tell you!

Play 2.4.0 “Damiya” released, adds new DI support and test APIs
Play 2.4 FINALLY adds built in DI — using Guice, my favorite Java DI container. They also look like they’ve added some useful methods for adding mock dependencies to FakeApplications when unit testing.

The U.S. Navy’s Big Mistake — Building Tons of Supercarriers
Super carriers are great for power projection — as long as you aren’t fighting a technologically even foe.

R.R. Wilson’s Congressional Testimony, April 1969

Posted: June 4th, 2015 | Author: | Filed under: Science | Tags: , | No Comments »

Going through some old links, I rediscovered this old testimony. This is the most beautiful defense of scientific research I have ever seen:

SENATOR PASTORE. Is there anything connected in the hopes of this accelerator that in any way involves the security of the country?

DR. WILSON. No, sir; I do not believe so.

SENATOR PASTORE. Nothing at all?

DR. WILSON. Nothing at all.

SENATOR PASTORE. It has no value in that respect?

DR. WILSON. It only has to do with the respect with which we regard one another, the dignity of men, our love of culture. It has to do with those things.

It has nothing to do with the military. I am sorry.

SENATOR PASTORE. Don’t be sorry for it.

DR. WILSON. I am not, but I cannot in honesty say it has any such application.

SENATOR PASTORE. Is there anything here that projects us in a position of being competitive with the Russians, with regard to this race?

DR. WILSON. Only from a long-range point of view, of a developing technology. Otherwise, it has to do with: Are we good painters, good sculptors, great poets? I mean all the things that we really venerate and honor in our country and are patriotic about.

In that sense, this new knowledge has all to do with honor and country but it has nothing to do directly with defending our country except to help make it worth defending.

MultiLinks 5-29-2015

Posted: May 29th, 2015 | Author: | Filed under: MultiLinks | No Comments »

In College and Hiding From Scary Ideas

This is the best thing I’ve read this week, possibly the best thing I’ve read this year. I couldn’t find a single point of disagreement.


I Fooled Millions Into Thinking Chocolate Helps Weight Loss. Here’s How.

This is the 2nd best thing I’ve read this week. Journalists who don’t understand how science works mislead people who also don’t understand how science works, in pursuit of readership.


Arms control treaty could land security researchers like me in jail

Once again, software is being subjected to arms trade regulations. We did this in the 90’s, and it lead to SSL downgrade attacks like POODLE and FREAK, which hurt everyone — including the government responsible for forcing their adoption. This foolishness will bite us, hard.


Higgs Machine Learning Challenge

Crowdsourced data science and ML algorithms being used to solve problems in high energy physics? Oh be still, my beating heart!


10 Books Every Programmer Should Read

I really love everything Javin Paul writes about Java. I haven’t read all of these, but I can highly recomment GOF Design Patterns, The Mythical Man Month, Martin Fowler’s Refactoring, and Joshua Bloch’s Effective Java.


TDD Gamification

I really don’t think this would work well for production development. However, this could be an amazing system for training new developers in TDD.


How can we Build Better Complex Systems? Containers, Microservices, and Continuous Delivery.

Long title, and an extremely long article, summarizing a talk (which I didn’t watch). It has a great summary of principles for developing microservices. I strongly agree with this point:

While microservices certainly lower friction they also increase risk from wiring hell and bad partitioning.

I’ve experienced wiring hell and bad partitioning (particularly, wiring hell from bad partitioning). It’s a real problem, and a good example of why, as the article says:

Microservices usually grow successfully from monoliths. In creating a monolith developers learn how to properly partition a system.

I love microservice architectures, but they must be approached correctly.


8 Questions You Need to Ask About Microservices, Containers & Docker in 2015

I love Docker and containers. However, they raise some very salient issues. Points 2 and 3, in particular, have been challenging me lately. Point 6, however, is the elephant in the Docker room, and leads directly into the next link…


Over 30% of Official Images in Docker Hub Contain High Priority Security Vulnerabilities

… Yeah. We need to get on top of this. For deployment, nocache is your friend…


Harvard’s Asian-American Quota Turns Diversity on Its Head

Apparently, it’s ok to be racist against successful minorities.

Kicking the tires…

Posted: May 26th, 2015 | Author: | Filed under: Personal | No Comments »

Maybe I should write more here. I am paying for hosting, after all…

I’m going to try one lengthy post a month, and a weekly link roundup. We’ll see how this goes.



Understanding Multithreading Through (flawed) Analogies

Posted: July 31st, 2014 | Author: | Filed under: Programming | Tags: | No Comments »

All through the 90’s, the performance of CPUs grew at a breakneck pace. Each generation added more and more hardware features to make code run faster and faster. As transistor technology continued to advance, CPU manufacturers pushed exotic and complex tricks and logic into their CPUs. They added advanced logic to predict the next instruction, to dynamically reordering code instructions, to merge and break apart groups of instructions. This is an attempt to cram yet more work into each fraction of a second. However, in recent years CPU makers have found it increasingly harder to make meaningful performance gains in simple execution speed.

To make use of the extra transistors, CPU makers have glued together many CPU backends into a single CPU unit. Instead of building a bigger, more powerful engine in a car, we cram several engines into the car, and make them work together.

We call each of these engines “cores”. This has given us in the software world a bonanza of resources to work with. Unfortunately, taking use of those resources is a significant challenge.

What is a thread?
To take advantage of CPUs and CPU cores, we have a software concept called a “thread”. On a simple level, a thread is a container for a sequence of instructions, that an operating system can put on one core. We can have many threads running on one core, or many cores, or have only one thread running on one core with the other cores idle.

This is a lot to digest, so let’s look at some examples, using some real world analogies.

Several threads, one core
Let’s imagine a TA is grading student assignments. In this analogy, the TA is a core, and he treats each paper as a single thread. So he starts grading paper one, works on it for a minute, then stops. He starts grading paper two for a minute, then stops, and so on. When he has worked on all the papers for one minute, he goes back to the first one.

Several threads, several cores
So, as you can imagine, this poor TA is taking a really long time to finish. So the professor decides to speed it up by adding a second core, another TA.

Now, TA1 takes a paper, starts working on it for one minute. TA2 takes another paper, and starts working on it for one minute. Each then does the same pattern as before, grabbing a paper from the top of the pile, working on it, and putting it on the bottom.

Context switching
Now, as you have probably noticed, this is not very efficient. It would probably be faster for each TA to start a paper, grade it all the way through, then start the next paper. It takes time to put a paper back, pick up a new paper, read the paper, figure out how far along the paper has been graded, and start working on it again. This is, however, the way computers work; this is a very real performance cost, called “context switching”. So why do we do work like this on computers? Because usually, the tasks each thread needs to run don’t all take the same amount of time. Some tasks take a really long time to complete (such as burning to a CD). Some tasks are very fast, like scrolling down a document or webpage. Sure, if we didn’t switch threads, burning a CD might complete a few seconds sooner; but would you really want your entire computer to lock up for several minutes while that task completed?

Parallel Algorithms
As you can see, using multiple threads can speed up completing a task, but at a cost of context switching. There are many ways we can use threads to speed up tasks, but they come with many other pitfalls, as well. Let’s look at ways to use multiple threads to speed up tasks.

For this example, we will look at cashiers ringing up groceries at a store. Let’s ignore the problem of context switching; lets pretend we have infinite cores.

Single threaded
Let’s take a case of one cashier (thread). There is only one line. The one cashier rings up the groceries, bags them, and assists taking the groceries to the car. Obviously, this does not scale well, as the line gets longer. So how do we use two cashiers?

First, we can use them in parallel. Each cashier gets a line, and assist shoppers at the same time. Another way to use them is to create a pipeline. One cashier rings up shoppers, while the second bags the groceries and assists shoppers to the car.

Note that these can be done together. If we have four cashiers, we can create two pipelines, and assist two lines of shoppers at the same time. Also note that while this can improve throughput, it also increases cost. However, it  doesn’t always increase throughput; if there aren’t enough shoppers, most of the cashier threads are going to be idle, waiting for a job to do. Another issue is that, when using a pipeline, the work can be stalled if one task, such as taking groceries to a car, takes much longer than other tasks, such as ringing up, or bagging groceries.

Thread Pooling
How can we use threads more efficiently? Instead of tying each person to a specific task, we let each of them take whatever task is available. We have three tasks (ringing up, bagging, assisting to car), and a group of three cashiers. This group of cashiers are called a thread pool.

Each cashier then takes whatever task is available. If the cashier who assists to the car is not back when the cashier finishes bagging, that cashier then assists to the car, and so on. Of course, this can lead to issues, as well. If assisting to the car takes a very long time, it’s possible that all three cashiers are busy assisting, and no one is ringing up customers. So we need to prioritize the tasks. We assign ringing up as a high priority, bagging as a medium priority, and assisting to the car as a low priority. Now, a cashier will only take the highest priority task that is available. The cashier bagging groceries will only assist someone to the car if there are no more groceries to bag. This is called priority scheduling.

Resource Contention
So, how do we use two cashiers in parallel? Well, let’s try having them both check out people on the same register. That doesn’t work at all, because one person’s grocery bill is getting mixed in with another, and leaving the bill in an entirely incoherent state. So we need to manage access to the register. In programming terms, the first cashier will “lock” the thread while ringing up groceries, then “unlock” it when finished. Then the next cashier can take control and start ringing up the next customer. Now, we have fixed the data integrity issue, but introduced a very serious performance bottleneck. This is called resource contention.

There is also another potential issue this has introduced. Imagine the cashier who has locked the register gets a call, to handle an emergency. The cashier then goes on break to handle the emergency, but forgets to unlock the register. Now the other cashier and all the customers have to wait. If the first cashier never comes back, the customers and other cashier will be waiting forever. This is called deadlocking.

Solving Resource Contention
The easiest way to solve this issue with resource contention is to not share resources. In our grocery store, we solve the issue by installing a 2nd cash register. Now, both clerks can process customers at the same time, without interfering with each other. But this came with some cost, the cost of buying a cash register; in computers this comes with cost too; more memory, and more time spent building the resources. Additionally, we now have two sets sales records that now have to be rectified.

Sometimes, we simply have to share resources. In this example, let’s add a manager. We want there to be only one manager, as only one person should have the accountability and responsibility for certain problems. Now, only one clerk can use the manager at a time. Imagine a clerk calls the manager over, and says, “hey, I might have a problem, so stay here just in case.” Now, that manager is “in use”, and any other clerk who needs manager assistance has to wait. This is another bottleneck. To alleviate this, we instruct our clerks to only call the manager when needed, and let the manager leave when the problem is resolved. Minimizing the time a shared resource is locked can significantly improve performance, and minimize the chance of deadlocking.

There are many more possible problems when dealing with multithreading: Live locking, false sharing, and race conditions to name a few. Even when we write correct multithreaded code, it can be hard to extract serious performance benefits. CPU makers continue to give us more and more raw power, but using that power to actually benefit the user is a significant challenge for programmers to overcome.