atomicity

Ensuring Atomicity sql

Hi, I was just reading about RDBMS, and one property of an RDBMS is atomicity. So, if money is withdrawn from an account and transferred to another, either the transaction will happen completely or not at all. There are no partial transactions. But how is actually ensured? Sql queries for the above scenario might look like (i) UPDATE ac...

Accessing object members and atomicity

We know from the C# specification that reference read/writes are atomic. In a statement that accesses member of an object, will the reference also be accessed atomically? I think yes because it is also a kind of implicit reference read which the compiler must provide atomicity for while generating code for it. In the same statement, ac...

Atomic Instruction

What do you mean by Atomic instructions? How does the following become Atomic? TestAndSet int TestAndSet(int *x){ register int temp = *x; *x = 1; return temp; } From a software perspective, if one does not want to use non-blocking synchronization primitives, how can one ensure Atomicity of instruction? is it possible only a...

In C is "i+=1;" atomic?

In C, is i+=1; atomic? ...

What does AtomicReference.compareAndSet() use for determination?

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...

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

In my multithreaded asmx web service I had a class field _allData of my own type SystemData which consists of few List<>s and Dictionary<>s marked as volatile. The system data (_allData) is refreshed once in a while and I do it by creating another object called newData and fill it's data structures with new data. When it's done I just as...

Atomic file copy under .NET

I am building a server app that copies files using System.IO.File.Copy(...) function. My files can be rather large, therefore, it has a fair chance that if the machine crashes, it happens during copying. After restarting the service, I should be able to pick up the copy tasks and continue. How can I detect if a copy has been successfull...

Functions for performing atomic operations.

Are there functions for performing atomic operations (like increment / decrement of an integer) etc supported by C Run time library or any other utility libraries? If yes, what all operations can be made atomic using such functions? Will it be more beneficial to use such functions than the normal synchronization primitives like mutex ...

Portable c++ atomic swap (Windows - GNU/Linux - MacOSX)

Hi, Is there free a portable (Windows, GNU/Linux & MacOSX) library providing a lock-free atomic swap function? If not, how would it be implemented for each of these platforms? (x86 with VC++ or g++) Thanks ...

How can I implement an atomic incr and decr on top of an eventually consistent key-value store?

How can I implement an atomic incr and decr on an eventually consistent key-value store? Is this even possible? Does being eventually consistent mean that I just have to accept that a value will never be for sure? ...

basic SQL atomicity "UPDATE ... SET .. WHERE ..."

I have a rather basic and general question about atomicity of "UPDATE ... SET .. WHERE ..." statement. having a table (without extra constraint), +----------+ | id | name| +----------+ | 1 | a | +----+-----+ now, I would execute following 4 statements "at the same time" (concurrently). UPDATE table SET name='b1' WHERE name='a' UP...

unique constraint (w/o Trigger) on "one-to-many" relation

To illustrate the problem, I make an example: A tag_bundle consists of one or more than one tags. A unique tag combination can map to a unique tag_bundle, vice versa. tag_bundle tag tag_bundle_relation +---------------+ +--------+ +---------------+--------+ | tag_bundle_id | | tag_id...

Handling transaction context using method attribute in linq to sql

Is there a way to just put an attribute to a method so that the whole code in the method is executed in a transaction scope? I've seen this done in sharp architecture but I'm using Linq to sql not nhibernate. Thanks! This what I would like to do: [Transaction] public void InsertCustomer(Customer customer) { //insert customer } So th...

Lock-Free Data Structures in C++ Compare and Swap Routine

In this paper: Lock-Free Data Structures (pdf) the following "Compare and Swap" fundamental is shown: template <class T> bool CAS(T* addr, T exp, T val) { if (*addr == exp) { *addr = val; return true; } return false; } And then says The entire procedure is atomic But how is that so? Is it not possible that some ...

How to write a spinlock without using CAS

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...

Atomicity guarantees on Winsocks?

As Windows doesn't provide UNIX domain sockets, I am using a a local TCP connection to simulate the behaviour. Now, POSIX guarantees that if several threads are writing to the UNIX domain socket in parallel, chunks up to PIPE_BUF will be handled atomically - i.e. no interleaving will happen. Is there are similar guarantee on local TCP wi...

How to move an element in a sorted list and keep the CouchDb write "atomic"

I have elements of a list in couchdb documents. Let's say these are 3 elements in 3 documents: { "id" : "783587346", "type" : "aList", "content" : "joey", "sort" : 100.0 } { "id" : "358734ff6", "type" : "aList", "content" : "jill", "sort" : 110.0 } { "id" : "abf587346", "type" : "aList", "content" : "jack", "sort" : 120.0 } A view ret...

Cocoa nonatomic properties

When you look at some Objective-C code, you often see class properties defined as non-atomic. Why? Does it give you some performance boost when you're not working with threads, or is there some other reason? ...

Is SPLFileObject atomic?

I'm wondering whether methods of PHPs SPLFileObject are atomic (e.g. thread-safe) or not? If they aren't, I'll implement my own class, which will use flock(), but is this enough? Is the flock function really thread-safe? What if the collision occurs after I fopen() the file, but before I flock() it? ...

MySQL and PHP: Atomicity and re-entrancy of a PHP code block executing two subsequent queries - how dangerous?

In MySQL I have to check whether select query has returned any records, if not I insert a record. I am afraid though that the whole if-else operation in PHP scripts is NOT as atomic as I would like, i.e. will break in some scenarios, for example if another instance of the script is called where the same record needs to be worked with: i...