Does Thread.yield() do anything if we have enough processors to service all threads?

Whenever a thread calls the Thread.yield() method, it gives a hint to the thread scheduler that it is ready to pause its execution. The thread scheduler is free to ignore this hint. If any thread executes the yield method, the thread scheduler checks if there is any runnable (waiting to be executed) thread with same …

Read more

Optimistic Locking by concrete (Java) example

Normally when you look into optimistic locking you also use a library like Hibernate or an other JPA-Implementation with @Version support. Example could read like this: public class Person { private String firstName; private String lastName; private int age; private Color favoriteColor; @Version private Long version; } while obviously there is no point of adding …

Read more

Can modern x86 hardware not store a single byte to memory?

TL:DR: On every modern ISA that has byte-store instructions (including x86), they’re atomic and don’t disturb surrounding bytes. (I’m not aware of any older ISAs where byte-store instructions could “invent writes” to neighbouring bytes either.) The actual implementation mechanism (in non-x86 CPUs) is sometimes an internal RMW cycle to modify a whole word in a …

Read more