atomic

Atomic increment on mac OS X

I have googled for atomic increment and decrement operators on Mac OS X and found "OSAtomic.h", but it seems you can only use this in kernel space. Jeremy Friesner pointed me at a cross-platform atomic counter in which they use assembly or mutex on OS X (as far as I understood the interleaving of ifdefs). Isn't there something like Int...

A common way to make checking for nonexistence of a row and inserting it atomic?

I have a web-application. The flow of processing a form in it goes like this: Validate List errors or Insert/update the data In this particular scenario I'm developing a user registration process but I'm trying to find a common solution for all types of forms bases on checking availability of unique value in a database table. In thi...

Do you expect that future CPU generations are not cache coherent?

I'm designing a program and i found that assuming implicit cache coherency make the design much much easier. For example my single writer (always the same thread) multiple reader (always other threads) scenarios are not using any mutexes. It's not a problem for current Intel CPU's. But i want this program to generate income for at leas...

Is a lock (threading) atomic?

This may sound like a stupid question, but if one locks a resource in a multi-threaded app, then the operation that happens on the resource, is that done atomically? I.E.: can the processor be interrupted or can a context switch occur while that resource has a lock on it? If it does, then nothing else can access this resource until it'...

Can competing atomic operations starve one another?

Imagine a program with two threads. They are running the following code (CAS refers to Compare and Swap): // Visible to both threads static int test; // Run by thread A void foo() { // Check if value is 'test' and swap in 0xdeadbeef while(!CAS(&test, test, 0xdeadbeef)) {} } // Run by thread B void bar() { while(1) { ...

Is fwrite atomic?

A simple question: I need to add some logging to my program. If two processes use "fwrite" on the same file but not the same file descriptor will the written log messages be atomic or mixed. Is there a length limit? Is it defined ANSI-C behaviour or implementation defined? If the later what is on MacOSX, Linux and Windows MSVC? ...

Is File.Delete() atomic under .NET

Target OS: Win2003 As posted in other SO questions about file operation atomicity, Win32 was simply not designed for transactions. Still I wonder whether file deletion could be non-atomic. After all, it is either get deleted or not. Or can a file remain in any other intermediate state on NTFS file system caused by a system crash or som...

C# multithreaded list operations

If I have something like this (pseudocode): class A { List<SomeClass> list; private void clearList() { list = new List<SomeClass>(); } private void addElement() { list.Add(new SomeClass(...)); } } is it possible that I run into multithreading problems (or any kind of unexpected behavior) w...

Is BOOL read/write atomic in Objective C?

What happens when two threads set a BOOL to YES "at the same time"? ...

How to perform atomic operations on Linux?

Every Modern OS provides today some atomic operations: Windows has Interlocked* API FreeBSD has <machine/atomic.h> Solaris has <atomic.h> Mac OS X has <libkern/OSAtomic.h> Anything like that for Linux? I need it to work on most Linux supported platforms including: x86, x86_64 and arm. I need it to work on at least GCC and Intel C...

Thread-safe cache libraries for .NET

Background: I maintain several Winforms apps and class libraries that either could or already do benefit from caching. I'm also aware of the Caching Application Block and the System.Web.Caching namespace (which, from what I've gathered, is perfectly OK to use outside ASP.NET). I've found that, although both of the above classes are te...

atomic writing to file with Python

I am using Python to write chunks of text to files in a single operation: open(file, 'w').write(text) If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done? ...

Atomic Increment & Fetch

Hi, I'm looking for a way to atomically increment a short, and then return that value. I need to do this both in kernel mode and in user mode, so it's in C, under Linux, on Intel 32bit architecture. Unfortunately, due to speed requirements, a mutex lock isn't going to be a good option. Is there any other way to do this? At this point, ...

asm/atomic.h compile error

I have an old C++ project and I'm having problem building it. For a certain file I receive the following kind of errors: error: ‘atomic_t’ was not declared in this scope And others for other identifiers like atomic_read, atomic_inc, etc. The file has an include for asm/atomic.h, but I cannot find the header file on my system. I'm u...

C++0x atomic implementation in c++98 question about __sync_synchronize()

I have written the followin atomic template with a view to mimicing the atomic operations which will be available in the upcoming c++0x standard. However, I am not sure that the __sync_synchronize() call I have around the returning of the underlying value are necessary. From my understanding, __sync_synchronize() is a full memory barr...

any primitive data type in c# is automic(thread safe)?

For example, do i need to lock 'bool' value when doing multithreading? ...

Are the atomic builtins provided by gcc actually translated into the example code, or is that just for illustrative purposes?

So I was reading http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html, and came across this: type __sync_and_and_fetch (type *ptr, type value, ...) type __sync_xor_and_fetch (type *ptr, type value, ...) type __sync_nand_and_fetch (type *ptr, type value, ...) These builtins perform the operation suggested by the name, and ret...

how to atomically claim a row or resource using UPDATE in mysql

i have a table of resources (lets say cars) which i want to claim atomically. I then want information about which resource I just claimed. If there's a limit of one resource per one user, i can do the following trick: UPDATE cars SET user = 'bob' WHERE user IS NULL LIMIT 1 SELECT * FROM cars WHERE user = 'bob' This way, I claim the ...

Can CompareExchange be implemented with CompareAndSwap?

Assuming that CompareAndSwap (or CAS) never fails spuriously, can CompareExchange be implemented with CAS? CompareExchange both take a pointer, an expected value, and a new value and atomically set the memory referenced by the pointer to the new value if it matches the expected value. The difference between the two is that CompareExcha...

Are +=, |=, &= etc atomic?

Are the "modify" operators like +=, |=, &= etc atomic? I know ++ is atomic (if you perform x++; in two different threads "simultaneously", you will always end up with x increased by 2, as opposed to x=x+1 with optimization switched off.) What I wonder is whether variable |= constant, and the likes are thread-safe or do I have to protec...