atomicity

Atomic counters in Spring with Couchbase

↘锁芯ラ 提交于 2019-12-07 16:53:50
问题 Is it possible to use Couchbase's Atomic Counters with the Spring Connector? Currently I have a repository for a specific document type and want to have an atomic counter for every document. I know that the Java SDK offers the functionality but I was not able to find an equivalent action for Spring. 回答1: As I know Spring doesn't have support for counters but it's pretty simple to write own repository: @Repository public class CountersRepository { private static final long INITIAL_COUNTER

What is atomic?

为君一笑 提交于 2019-12-07 13:24:25
问题 These are two atomic operations: int value = 5; Object obj = new Object(); But when using a primitive as a method parameter, would this be considered as an atomic operation: public void setValue(int val, Object obj){ this.value = val; // Atomic? this.obj = obj; // Not atomic? } ? The copy of the object reference is not atomic since it includes a read and a write, right? Would it be correct to say that the only way to make an atomic operation on an object reference is to declare it null or

MySQL command line and transactions

感情迁移 提交于 2019-12-07 03:11:43
问题 I have a question about MySQL and have been unable to find an answer. I know auto-commit is turned on by default in MySQL. I need to run a few update queries from the command line in one transaction but I don't know how MySQL will handle them. If I have something like this: mysql -uroot -proot -e 'QUERY 1; QUERY 2; QUERY3' will it execute as one transaction or will MySQL auto-commit each statement individually? I need to ensure atomicity. 回答1: You can use MySQL's START TRANSACTION syntax to

Atomic state storage in Python?

情到浓时终转凉″ 提交于 2019-12-06 16:56:57
问题 I'm working on a project on an unreliable system which I'm assuming can fail at any point. What I want to guarantee is that if I write_state and the machine fails mid-operation, a read_state will either read a valid state or no state at all. I've implemented something which I think will work below -- I'm interested in criticism of that or alternative solutions if anyone knows of one. My idea: import hashlib, cPickle, os def write_state(logname, state): state_string = cPickle.dumps(state,

Tools to experiment with weakly ordered concurrency

ぃ、小莉子 提交于 2019-12-06 13:06:13
What tools exist to help one to experiment with weakly ordered concurrency? That is, in what sandbox can one play while teaching oneself about partial fences, weak atomics, acquire/consume/release semantics, lock-free algorithms and the like? The tool or sandbox one wants would exercise and stress one's weakly ordered, threaded algorithm, exposing the various ways in which the algorithm might theoretically fail. Physically running on an x86, for example, the tool would nevertheless be able to expose ARM-type failures. An open-source tool would be preferable. Please advise. References: the C+

Workings of AtomicReferenceArray

主宰稳场 提交于 2019-12-06 05:11:10
I am wondering if AtomicReferenceArray can be used as a replacement for ConcurrentLinkedQueue (if one could live with a bounded structure). I currently have something like: ConcurrentLinkedQueue<Object[]> queue = new ConcurrentLinkedQueue<Object[]>(); public void store(Price price, Instrument instrument, Object[] formats){ Object[] elements = {price, instrument, formats}; queue.offer( elements); } The store(..) is called by multiple threads. I also have a consumer thread, which periodically wakes up and consumes the elements. private class Consumer implements Runnable{ @Override public void

atomic file creation on Linux?

丶灬走出姿态 提交于 2019-12-06 04:27:34
I need to create a file if it does not exist, in a way that another process trying to create this file would fail. I need the file be considered "created" even before the creating process finished writing the actual data to it. I read about O_EXCL flag to open() , so it seems that the solution exists, I have a few questions however: do you have experience with this technique? How good is it? (I guess I can't have a DB-level atomicity, but but good enough is... well, enough) should I immediately close the file after open() so that it is considered created, and then reopen it for writing? are

Memory ordering behavior of std::atomic::load

旧巷老猫 提交于 2019-12-06 03:44:21
问题 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 do the trick if (arm2.load()) triggered = true; Thread2: arm2.store(true); if (arm1) triggered = true; I expected that after executing both

What does AtomicReference.compareAndSet() use for determination?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 03:10:49
问题 Say you have the following class public class AccessStatistics { private final int noPages, noErrors; public AccessStatistics(int noPages, int noErrors) { this.noPages = noPages; this.noErrors = noErrors; } public int getNoPages() { return noPages; } public int getNoErrors() { return noErrors; } } and you execute the following code private AtomicReference<AccessStatistics> stats = new AtomicReference<AccessStatistics>(new AccessStatistics(0, 0)); public void incrementPageCount(boolean

Atomicity of Reads and Writes for Variables in Java

时间秒杀一切 提交于 2019-12-06 03:09:39
this is a followup on another question of mine . @templatetypedef answered the question (appreciated), and in his answer he wrote: As a note - atomicity does not mean "all other threads will be blocked until the value is ready. It means all other threads will either see the state purely before the operation is done or purely after the operation is done, but nothing else. I have a confusion regarding this, and here’s why: It says here : Atomic actions cannot be interleaved, so they can be used without fear of thread interference. What I infer from this, is that it contradicts what he wrote. If