Posts

Showing posts with the label Optimization

[Java] Volatile

1) Volatile Used as an indicator to Java Compiler and Thread to not cache value of this variable and always read it from the main memory . In multi-threaded environment, threads might cache variables locally. Volatile (or synchronization) ensures the variable is read from main memory. Makes variable atomic by implementation.  Only possible with variables ; cannot be used with method or class (illegal operation) Guarantees visibility and ordering; write to any volatile variable happens before any read. Prevents compiler or JVM form reordering code or moving away them away form synchronization barrier.  2) Example private boolean bExit ; while (! bExit ) { checkUserPosition (); updateUserPosition (); } The focus here is the variable, bExit.  One Thread (Game Thread) can cache the value of bExit instead of getting it form main memory everytime. If in between, any other thread (Event handler thread) changes the value; it would...

[Optimization] Parallel Computing, Concurrent Computing and Threading

Image
Parallel Computing =/= Concurrent Computing. What is threading? Parallel computing is a type of computation in which many calculations or the execution of processes are carried out simultaneously . Large problems can often be divided into smaller ones, which can then be solved at the same time. There is no taking turns, they are advanced at the same time. Naturally this is not possible with single-core CPU, but multiple-core architecture is required instead. It can be said that if computation is parallel it is also concurrent (but not necessarily the other way around) - since parallel computation also fulfills the definition of concurrent computation. Concurrent computing is a form of computing in which several computations are executed during overlapping time periods — concurrently —instead of sequentially (one completing before the next starts). This is not exactly same as Parallel computing . Concurrent operation means that two computations can both make progress an...