atomic

Are reads and writes to properties atomic in C#?

Reads and writes to certain primitive types in C# such as bool and int are atomic. (See section 5.5, "5.5 Atomicity of variable references", in the C# Language Spec.) But what about accessing such variables via properties? Is it reasonable to assume that they will also be atomic and thread-safe? E.g. Is a read of MyProperty below atom...

Django, how to make a view atomic?

I have a simple django app to simulate a stock market, users come in and buy/sell. When they choose to trade, the market price is read, and based on the buy/sell order the market price is increased/decreased. I'm not sure how this works in django, but is there a way to make the view atomic? i.e. I'm concerned that user A's actions m...

why does git allow remote tags to move, or why you can't use git-tag for atomic test-and-set

I have a problem where two similar processes are running in parallel within separate clones of the same repository (typically on different computers). Each time a process runs, it fetches the latest tags from the remote and then deduces a unique number based on the tags it sees. E.g. if these tags exist on the remote: 1.0 1.1 1.2 1.3 th...

What are atomic store types?

Hi, I've read the Core Data references on Apple's site. But I wonder, what they mean with atomic store types? They write something of "they have to be read and written in their entirety". Could somebody clarify this, please? ...

Why is there no overload of Interlocked.Add that accepts Doubles as parameters?

I fully appreciate the atomicity that the Threading.Interlocked class provides; I don't understand, though, why the Add function only offers two overloads: one for Integers, another for Longs. Why not Doubles, or any other numeric type for that matter? Clearly, the intended method for changing a Double is CompareExchange; I am GUESSING ...

alignment requirements for atomic x86 instructions

Microsoft offers the InterlockedCompareExchange function for performing atomic compare-and-swap operations. There is also an _InterlockedCompareExchange intrinsic. On x86 these are implemented using the cmpxchg instruction. However, reading through the documentation on these three approaches, they don't seem to agree on the alignment r...

About atomicity guarantee in C

On x86 machines, instructions like inc, addl are not atomic and under SMP environment it is not safe to use them without lock prefix. But under UP environment it is safe since inc, addl and other simple instructions won't be interrupted. My problem is that, given a C-level statement like x = x + 1; Is there any guarantees that C com...

AtomicInteger lazySet and set

May I know what is the difference among lazySet and set method for AtomicInteger. javadoc doesn't talk much about lazySet : Eventually sets to the given value. It seems that AtomicInteger will not immediately be set to the desired value, but it will be scheduled to be set in some time. But, what is the practical use of this method? Any...

Disable Hardware & Software Interrupts

Hello! Is it possible to disable all interrupts with a ASM/C/C++ program to get full control about the processor? If yes -> how? If not -> how do "atomic" operation system calls work (for example entering a critical section)? Sorry for my English! Thanks for your help! ...

Can I atomically increment a 16 bit counter on x86/x86_64?

I want to save memory by converting an existing 32 bit counter to a 16 bit counter. This counter is atomically incremented/decremented. If I do this: What instructions do I use for atomic_inc(uint16_t x) on x86/x86_64? Is this reliable in multi-processor x86/x86_64 machines? Is there a performance penalty to pay on any of these a...

Bitfield masks in C

Is there a portable way in C to find out the mask for a bit field at compile time? Ideally, I'd like to be able to atomically clear a field like this: struct Reference { unsigned age : 3; unsigned marked : 1; unsigned references : 4; }; struct Reference myRef; __sync_and_and_fetch(&myRef, age, ~AGE_MASK); Otherwise I hav...

Atomicity of Data Adapter in ADO.NET

Hi, I am new to ADO.NET and learning it. I was wondering if Data Adapter in ADO.NET provides atomicity or ACID properties by itself when filling the Data Set and updating the Database or do we have to use transaction explicitly to achieve this. Lets say, I want to fetch data from the Database through the Data Adapter to a Data Set Se...

Do atomic operations work the same across processes as they do across threads?

Obviously, atomic operations make sure that different threads don't clobber a value. But is this still true across processes, when using shared memory? Even if the processes happen to be scheduled by the OS to run on different cores? Or across different distinct CPUs? Edit: Also, if it's not safe, is it not safe even on an operating sys...

When are lock free data structures less performant than mutual exclusion (mutexes)?

I read somewhere (can't find the page anymore) that lock free data structures are more efficient "for certain workloads" which seems to imply that sometimes they're actually slower or the gain from them can be zero in some situations. Taking the ~100 cycle hit of a lock instruction to do an atomic op sounds plenty faster to me than going...

Do atomic operations become slower as more CPUs are added?

x86 and other architectures provide special atomic instructions (lock, cmpxchg, etc.) that allow you to write 'lock free' data structures. But as more and more cores are added, it seems as though the work these instructions will actually have to do behind the scenes will grow (at least to maintain cache coherency?). If an atomic add take...

Are partially updated values when multithreading still a concern on modern CPUs?

From the Wikipedia article on Read-Copy-Update: The reason that it is safe to run the removal phase concurrently with readers is the semantics of modern CPUs guarantee that readers will see either the old or the new version of the data structure rather than a partially updated reference. Is this true for all modern CPUs (ARM, x86, ...

What is the value of atomic commits in Subversion?

I'm trying to create and follow best practices for versioning control and came across a reference to atomic commits in subversion. Since I've never heard of this action, I have a few questions about it. What's its purpose? When should it be used? How is it different than a normal commit? Is it available to TortoiseSVN users? If so, h...

Atomic Instructions and Variable Update visibility

On most common platforms (the most important being x86; I understand that some platforms have extremely difficult memory models that provide almost no guarantees useful for multithreading, but I don't care about rare counter-examples), is the following code safe? Thread 1: someVariable = doStuff(); atomicSet(stuffDoneFlag, 1); Thread...

If more than one thread can access a field should it be marked as volatile?

Reading a few threads (common concurrency problems, volatile keyword, memory model) I'm confused about concurrency issues in Java. I have a lot of fields that are accessed by more than one thread. Should I go through them and mark them all as volatile? When building a class I'm not aware of whether multiple threads will access it, so s...

Atomic delete for large amounts of files

I am trying to delete 10000+ files at once, atomically e.g. either all need to be deleted at once, or all need to stay in place. Of course, the obvious answer is to move all the files into a temporary directory, and delete it recursively on success, but that doubles the amount of I/O required. Compression doesn't work, because 1) I don...