Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
114 views

Here is a Java class that writes messages in a parallel thread to a stream. When the stop() method is called, the mCloseWriter flag is set and the thread that writes the messages to the stream is ...
Igor Yarmolyk's user avatar
3 votes
0 answers
50 views

When using AsynchronousSocketChannel.write to transmit a message, class Transmitter(channel: AsynchronousSocketChannel) { def transmit(bytes: Array[Byte])(onComplete: Consumer[String]): ...
Readren's user avatar
  • 1,290
0 votes
1 answer
145 views

Does the synchronized lock guarantee the following code always print 'END'? public class Visibility { private static int i = 0; public static void main(String[] args) throws ...
Anonemous's user avatar
  • 319
3 votes
1 answer
239 views

I am confused about final field semantics in java. I've read 17.5 paragraph jls and found this example: class FinalFieldExample { final int x; int y; static FinalFieldExample f; ...
Роман Григорьев's user avatar
1 vote
2 answers
418 views

Within ConcurrentHashMap.compute() I increment and decrement some long value located in shared memory. Read, increment/decrement only gets performed within compute method on the same key. So the ...
Kirill's user avatar
  • 8,388
5 votes
0 answers
265 views

I'm trying to understand if there are any visibility-guarantees provided by CompletableFuture. Suppose I've a class called SampleClass which is something like the following: public class SampleClass ...
Lavish Kothari's user avatar
1 vote
1 answer
1k views

Threads A and B are executing concurrently. Which ARMv8-A memory barrier types (like DMB, DSB) are sufficient to fulfill the postcondition, and why? Initially x1 = 0, x2 = 0 Thread A | ...
user avatar
5 votes
3 answers
2k views

Context  I am writing a thread-safe protothread/coroutine library in C++, and I am using atomics to make task switching lock-free. I want it to be as performant as possible. I have a general ...
RmbRT's user avatar
  • 472
4 votes
2 answers
715 views

For which (if any?) STORE_ORDER & LOAD_ORDER does C++11 guarantee that this code runs in finite time? std::atomic<bool> a{false}; std::thread t{[&]{ while(!a.load(LOAD_ORDER)); }}; a....
Chronial's user avatar
  • 72k
4 votes
0 answers
391 views

I'm giving a presentation about the Go Memory Model. The memory model says that without a happens-before relationship between a write in one goroutine, and a read in another goroutine, there is no ...
stephenbez's user avatar
  • 5,668
0 votes
0 answers
64 views

I am on my cell phone now, so I have no code here. But it's simple. I have one static class working as a singleton in a web app. That class is called on the start of the application (when I use to ...
Caio Rodrigo's user avatar
14 votes
3 answers
2k views

Let's say I have a concurrent map with collections as value: Map<Integer, List<Integer> map = new ConcurrentHashMap<>(); map.putIfAbsent(8, new ArrayList<>()); and I update the ...
Marin Veršić's user avatar
4 votes
1 answer
180 views

I've looked at this answer, and it states how: Under the new memory model, when thread A writes to a volatile variable V, and thread B reads from V, any variable values that were visible to A at ...
Mario Ishac's user avatar
  • 6,117
0 votes
0 answers
253 views

Lately our system has been experiencing all kinds of Spring related 'voodoo'. It usually goes something like this: Various singleton beans have (ctor) autowired properties, based on which they ...
Vitaliy's user avatar
  • 8,225
0 votes
0 answers
41 views

Are there any guarantees to the variable visibility and/or ordering of instructions before Thread.start() in relation to the starting of the new thread? Specifically, in the minimalistic example ...
LoPoBo's user avatar
  • 1,877
1 vote
1 answer
273 views

public class Main { public static void main(String[] args) { Status status = new Status(); new Thread(new Runnable() { @Override public void run() { ...
lencha's user avatar
  • 11
13 votes
2 answers
2k views

Small question about memory visibility. CodeSample1: class CustomLock { private boolean locked = false; public boolean lock() { if(!locked) { locked = true; ...
JamesJenkins's user avatar
3 votes
1 answer
693 views

While reading "Java Concurrency in Practice", I came across the following - To publish an object safely, both the reference to the object and the object's state must be made visible to other threads ...
Ashutosh A's user avatar
  • 1,025
2 votes
2 answers
85 views

I have the following code to find the sum of natural numbers from 1 to 5000. It's a simple exercise to practice concurrency. public static void main(String[] args) throws InterruptedException { ...
Happy's user avatar
  • 1,865
6 votes
3 answers
409 views

I have read a few explanations of section 16.3 "Initialization Safety" from JCIP and am still not clear. The section states that "Further, any variables that can be reached through a final field of a ...
CaptainHastings's user avatar
2 votes
2 answers
432 views

I came across following example in book 'Java Concurrency in Practice'. public class NoVisibility { private static boolean ready; private static int number; private static class ...
Mandroid's user avatar
  • 7,818
4 votes
3 answers
697 views

if I have a byte queue, where it is expected to have one thread producer, another consumer: class ByteQueue{ byte[] buf; /*volatile?*/ int readIdx; /*volatile?*/ int writeIdx; ...
fbenoit's user avatar
  • 3,270
2 votes
2 answers
250 views

I'm getting a little unsure about what to expect from Concurrent Collections (e.g. ConcurrentMap) regarding visibility of the data in the collection. A: Thread1 puts a complex object and Thread2 gets ...
Stig's user avatar
  • 2,115
2 votes
3 answers
209 views

perlthrtut excerpt: Note that a shared variable guarantees that if two or more threads try to modify it at the same time, the internal state of the variable will not become corrupted. However, ...
user2050516's user avatar
0 votes
2 answers
156 views

If I use a BackgroundWorker to modify data structures in my application, is there a guarantee that changes made on the background thread will be visible to the main (UI) thread when the ...
adv12's user avatar
  • 8,551
4 votes
3 answers
748 views

Consider the code snippet class A { private Map<String, Object> taskMap = new HashMap<>(); private volatile Object[] tasksArray ; // assume this happens on thread1 public ...
Bhaskar's user avatar
  • 7,523
3 votes
1 answer
402 views

I'm trying to implement a fast version of LZ77 and I have a question to ask you about concurrent programming. For now I have a final byte[] buffer and a final int[] resultHolder, both of the same ...
Shepard's user avatar
  • 821
3 votes
3 answers
1k views

I know in Java visibility of a member is not guaranteed when accessing it from another thread. The meaning is the accessing thread will maybe see a stole value of the member (becuase the cache has ...
user1028741's user avatar
  • 2,855
1 vote
1 answer
199 views

Title might seem weird, so let me explain. Often people teaching about race conditions say thread1 can see x == 0 while thread 2 already did x=1; My questions is about threads scheduled on same core(...
NoSenseEtAl's user avatar
  • 30.9k
4 votes
1 answer
194 views

I have this simple piece of code. class A { static volatile String[] a = new String[9]; public static void main(String[] args) { new Thread() { public void run() { ...
Dog's user avatar
  • 7,827
4 votes
3 answers
2k views

Let's see this simple Java program: import java.util.*; class A { static B b; static class B { int x; B(int x) { this.x = x; } } public static ...
Dog's user avatar
  • 7,827
210 votes
5 answers
51k views

A sensitive operation in my lab today went completely wrong. An actuator on an electron microscope went over its boundary, and after a chain of events I lost $12 million of equipment. I've narrowed ...
Dog's user avatar
  • 7,827
3 votes
2 answers
629 views

Take a look at this simple Java program: import java.lang.*; class A { static boolean done; public static void main(String args[]) { done = false; new Thread() { ...
Dog's user avatar
  • 7,827
17 votes
2 answers
2k views

The following is from classical Concurency in Practice: When thread A writes to a volatile variable and subsequently thread B reads the same variable, the values of all variables that were ...
Cratylus's user avatar
  • 54.3k
12 votes
5 answers
3k views

I see this code quite frequently in some OSS unit tests, but is it thread safe ? Is the while loop guaranteed to see the correct value of invoc ? If no; nerd points to whoever also knows which CPU ...
krosenvold's user avatar
  • 77.6k
14 votes
4 answers
413 views

I'm trying to reproduce a memory visibility issue in case of insufficient object initialization for non-final fields (JLS 17.5 Final Field Semantics, FinalFieldExample class example). Where it stated "...
yetanothercoder's user avatar
6 votes
4 answers
806 views

While writing some java article I'm trying to reproduce re-ordering in case of unsynchronized object costruction in multithreaded environment. The case when a heavy object is constructed w/o ...
yetanothercoder's user avatar
1 vote
2 answers
444 views

The following class: class Pizza { Ingredients ingredients; Price price; public setIngredients(Ingredients ing) { if (ingredients != null) { throw new ...
Joonas Pulakka's user avatar
102 votes
7 answers
117k views

My teacher in an upper level Java class on threading said something that I wasn't sure of. He stated that the following code would not necessarily update the ready variable. According to him, the ...
dontocsata's user avatar
  • 3,091