All Questions
4 questions
1
vote
2
answers
141
views
Java multithread race condition, Min and Max range of a value
I have been asked this question recently in an interview, and I didn't get a feedback from my interviewer. I think the minimum answer is 2.
Given the following code, what will be the minimum and ...
2
votes
3
answers
714
views
Updating a Shared Resource in Multithreaded Program
Can someone explain the output of the following program:
public class DataRace extends Thread {
static ArrayList<Integer> arr = new ArrayList<>();
public void run() {
...
2
votes
3
answers
506
views
unsynchronized read/write of variables may cause data race?
in Java Performance Tuning by Jack Shirazi it writes:
This means that access and update of variables are automatically synchronized (as long as they are not longs or doubles). If a method consists ...
4
votes
1
answer
505
views
If two unsynchronized threads increment a counter X times, can the total result be less than X?
I have two unsynchronized threads in a tight loop, incrementing a global variable X times (x=100000).
The correct final value of the global should be 2*X, but since they are unsynchronized it will ...