Bloomberg LP Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

when a piece of code is shared between 2 threads
and when output of the code is different depending on the order in which that 2 threads execute that code...is race condition.

instead of code we can have any resources being shared here, instead of thread we can have processes.

- morpheus February 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Well, not necessary to be the same piece of code; should be "accessing" the same data, and at least one of the thread is doing "write".

- Haoju July 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Say, when in a system when one thread is partway from updating the data and the other thread access the same data, chaos is likely to occur and the result produced is not what expected and such kinds of bugs are called race condition where the threads racing one another to change the same data. To eliminate race conditions you need a way to make the operations atomic may be by employing some synchronization mechanism.

- Vivek July 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The key feature of a race condition is that it is not reproducible. Just like a car race if you run it N - times you will always get a differences (note you may get the same winner, just with a different time).

In the case of processes, it depends on how many are running, what they are doing, etc..

So another hallmark of race conditions is that they are notoriously hard to track down.

- Anonymous November 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Race condition occurs when two or more threads performs an operation and result of an operation depends on unpredictable timing factor. For Eg:
If two threads executes an routine and each increment a same variable such as x=x+1 the variable could incremented twice and one of the thread could use wrong value like below:
1) Thread A increments var x;
2) Thread A is interrupted ( or blocked, or scheduled off), and thread B is started.
3) Thread B starts and increments variable x;
4). Thread B is interrupted (or blocked, or scheduled off), and thread A is started.
5). Thread A check the value of x and performs action based on values of x. The value of x differs from when thread A incremented it, and program behaviur is incorrect.

- venkat December 16, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More