FAQ Database Discussion Community


Batch processing versus Single row transactions for atomicity

sql,oracle,perl,dbi,atomicity
I have two tables; one to hold records of reports generated, and the other to update a flag that the reports have been generated. This script will be scheduled, and the SQLs have been implemented. However, there are two implementations of the script: Case 1: - Insert all the records,...

atomic model save in django

django,atomicity
I've three models Question, Submission, UserResult. users submit an answer to a Question, this answer is scored by the system and stored in a Submission. The score of a user for one question is maximum amongst all of his/her submissions. This score is saved in a model called UserResult(it has...

How to create-then-atomically-rename file in Java on Windows?

java,windows,file-io,atomicity
I am trying to implement "write temporary file and rename" using Java on Windows correctly. How to atomically rename a file in Java, even if the dest file already exists? suggests renaming files is "atomic operation" (whatever "atomic" actually means). http://stackoverflow.com/a/20570968/65458 suggests writing tmp file and renaming is cross-platform and...

what is “failure atomicity” used by J bloch and how its beneficial in terms of immutable object?

java,object,immutability,atomicity
just came across below statement as benefit of immutable object Immutable object always have “failure atomicity” (a term used by Joshua Bloch) : if an immutable object throws an exception, it’s never left in an undesirable or indeterminate state. can any one explain it in more detail and why is...

Why to use AtomicRefernce when reading & setting simple reference is already atomic operation [duplicate]

java,concurrency,atomicity
This question already has an answer here: When to use AtomicReference (Java)? Is it really necessary? 1 answer Could somebody please clarify my doubt on AtomicReferences. As par java memory model reading & writing references is always an atomic operation irrespective of 32 bit or 64 bit machine. So...

Should getter and setter on String field of a thread have to be synchronized/

java,multithreading,atomicity
I am making a Runnable which will do some independent work but it's progress will be followed by other thread. In order to do that I put a private String field which contain "the state" of my thread. The thread will update his process by using the setter of this...

Is this a correct use case for AtomicReference in Java?

java,multithreading,atomicity
I have a processor cache class which is a singleton and has a Processor field. The Processor field will be set by a single Updating thread and used by many Worker threads. I don't know whether my current implementation is a appropriate usage of the AtomicReference. Would you please check...

Memory ordering behavior of std::atomic::load

c++,c++11,atomic,atomicity,memory-fences
Am I wrong to assume that the atomic::load should also act as a memory barrier ensuring that all previous non-atomic writes will become visible by other threads? To illustrate: volatile bool arm1 = false; std::atomic_bool arm2 = false; bool triggered = false; Thread1: arm1 = true; //std::std::atomic_thread_fence(std::memory_order_seq_cst); // this would...

AtomicBoolean vs Synchronized block, whats the difference

java,concurrency,synchronization,boolean,atomicity
I am trying to understand the difference between the two following code blocks AtomicBoolean ab = new AtomicBoolean(false); using the following to get and set state. . ab.get(); ab.set(X); vs. private boolean ab = false; private final Object myboollock = new Ojbect(); public void setAB(boolean state) { synchronized(myboollock) { ab...

Atomic boolean, test for current value

java,multithreading,atomic,atomicity
I have problems understanding the AtomicBoolean and how could i make best use of its method getAndSet(boolean newValue); Volatile makes all changes directly in memory, so if CPU cannot cache some value, visibility of changes is guaranteed between threads. Synchronized protects from race conditions. Is the following code thread safe...

Should load-acquire see store-release immediately?

c++,multithreading,atomic,atomicity
Suppose we have one simple variable(std::atomic<int> var) and 2 threads T1 and T2 and we have the following code for T1: ... var.store(2, mem_order); ... and for T2 ... var.load(mem_order) ... Also let's assume that T2(load) executes 123ns later in time(later in the modification order in terms of the C++...

Difference between getAndSet and compareAndSet in AtomicBoolean

java,synchronization,atomicity,atomicboolean
The thread title should be self-explnatory... I'm a bit confused between the specification of below methos from AtomicBoolean class: java.util.concurrent.atomic.AtomicBoolean#compareAndSet java.util.concurrent.atomic.AtomicBoolean#getAndSet My assemption is that both would result in the same behavior when used as a boolean clause in an if condition: public class Test { private AtomicBoolean flag =...

Can an updated with nested select be considered atomic in Sybase?

sql,sybase,atomicity
I am trying something like this: set rowcount 10 //fetch only 10 row Update tableX set [email protected] where id in (select id from tableX where x=0) basically mark 10 record as booked by supplying a batchId. So my question is if this proc is executed in parallel then can I...