atomicity

Rethinkdb atomic operations

时光总嘲笑我的痴心妄想 提交于 2019-12-10 14:32:32
问题 Let's say I have a document { id: 1, fruits: [] } fruits here acts as a SET Now I want to atomically add a value to fruits array for document with primary key = 1 OR create such document if it does not exist(i.e. use SetInsert ReQL under the hood) I also need to do the same for increment(ReQL .Add) Obviously this can't be done in client code as it breaks atomicity and I end up with inconsistent data I wish something like this was possible r.table('results').insert({ id: '62c70132-6516-4279

C# thread safe static member

给你一囗甜甜゛ 提交于 2019-12-10 14:02:42
问题 I have a C# class with a static member, that is read from multiple threads and written in one thread. As far as I know Uint64 read and write is not an atomic operation on all systems, so I have to manually guarantee thread safety. I had a few ideas about how to do this. Do it with and atomic wrapper class, like std::atomic in c++. Is there something similar implemented in C#? Use the volatile modifier with static field. However this is not allowed. Why? I finally did the following: private

Handling quorum writies fail on Cassandra

时光毁灭记忆、已成空白 提交于 2019-12-10 12:09:25
问题 According to Datastax documentation about atomicity in Cassandra: QUORUM write succeeded only on one node will not be rolled back (Check Atomicity chapter there:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_about_transactions_c.html). So when I am performing a QUORUM write on cluster with RF=3 and one node fails, I will get write error status and one successful write on another node. This produces two cases: write will be propagated to other nodes

atomic file creation on Linux?

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:44:22
问题 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

Workings of AtomicReferenceArray

[亡魂溺海] 提交于 2019-12-10 10:33:46
问题 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

Pop multiple values from Redis data structure atomically?

早过忘川 提交于 2019-12-10 01:09:56
问题 Is there a Redis data structure, which would allow atomic operation of popping (get+remove) multiple elements, which it contains? There are well known SPOP or RPOP, but they always return a single value. Therefore, when I need first N values from set/list, I need to call the command N-times, which is expensive. Let's say the set/list contains millions of items. Is there anything like SPOPM "setName" 1000 , which would return and remove 1000 random items from set or RPOPM "listName" 1000 ,

In C is “i+=1;” atomic?

亡梦爱人 提交于 2019-12-08 23:03:30
问题 In C, is i+=1; atomic? 回答1: The C standard does not define whether it is atomic or not. In practice, you never write code which fails if a given operation is atomic, but you might well write code which fails if it isn't . So assume it isn't. 回答2: No. The only operation guaranteed by the C language standard to be atomic is assigning or retrieving a value to/from a variable of type sig_atomic_t , defined in <signal.h> . (C99, chapter 7.14 Signal handling.) 回答3: Defined in C, no. In practice,

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

╄→尐↘猪︶ㄣ 提交于 2019-12-08 17:59:06
问题 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). https://stackoverflow.com/a/20570968/65458 suggests writing tmp file and renaming is cross-platform and ensures final file either does not exist or can be processed by the other process. So I tried to actually implement this approach. Below is

How to write a spinlock without using CAS

怎甘沉沦 提交于 2019-12-08 03:56:52
问题 Following on from a discussion which got going in the comments of this question. How would one go about writing a Spinlock without CAS operations? As the other question states: The memory ordering model is such that writes will be atomic (if two concurrent threads write a memory location at the same time, the result will be one or the other). The platform will not support atomic compare-and-set operations. 回答1: Wikipedia's article on spinlock says you'll have to use an algorithm like Peterson

Tools to experiment with weakly ordered concurrency

心已入冬 提交于 2019-12-07 22:13:18
问题 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