atomic

How to safely update a file that has many readers and one writer?

I have a set of files. The set of files is read-only off a NTFS share, thus can have many readers. Each file is updated occasionally by one writer that has write access. How do I ensure that: If the write fails, that the previous file is still readable Readers cannot hold up the single writer I am using Java and my current solution...

List of Delphi data types with 'atomic' read/write operations?

Are 'boolean' variables thread-safe for reading and writing from any thread? I've seen some newsgroup references to say that they are. Are any other data types available? (Enumerated types, short ints perhaps?) It would be nice to have a list of all data types that can be safely read from any thread and another list that can also be ...

Nonblocking algorithm to generate unique negative numbers

I recently refactored a piece of code used to generate unique negative numbers. edit: Multiple threads obtain these ids and add as keys to a DB; numbers need to be negative to be easily identifiable -at the end of a test session they're removed from the DB. My Java algorithm looks like this: private final Set<Integer> seen = Collec...

Is this a safe version of double-checked locking?

Slightly modified version of canonical broken double-checked locking from Wikipedia: class Foo { private Helper helper = null; public Helper getHelper() { if (helper == null) { synchronized(this) { if (helper == null) { // Create new Helper instance and store reference on ...

Objective-C properties: atomic vs nonatomic

What do atomic and nonatomic mean in property declarations? @property(nonatomic, retain) UITextField *userName; @property(atomic, retain) UITextField *userName; @property(retain) UITextField *userName; What is the functional difference between these 3? ...

can linq update and query atomically?

Hi, I need to get 1000 rows from a database, and at the same time tag them as 'in process'. This way, another thread can not take the same 1000 rows and process them as well. With linq i do something like this: msgs = (from m in database.messages where (m.status == MESSAGESTATUSINIT) select m).Take(1000).ToList(); ide...

Does x86 have an atomic increment that keeps the value that was stored?

I have found lock inc addr but that doesn't keep a copy of the stored value around and even a read immediately after it in the same thread could come after a competing write. The best solution I have found is a load/inc/cas loop. ...

MSSQL: What happens when an error occurs during trigger execution?

Regarding Update and Insert triggers for MS SQL Server, is there a way to make them atomic? In other words, if an error occurs during the trigger, is it possible to automatically roll back the original insert or update? ...

Is there a way to make a function atomic in C?

Is there a way to make a function atomic in C. I am not looking for a portable solution.(platforms looking for - Win,Linux) ...

Is there a way I can make two reads atomic?

I'm running into a situation where I need the atomic sum of two values in memory. The code I inherited goes like this: int a = *MemoryLocationOne; memory_fence(); int b = *MemoryLocationTwo; return (a + b) == 0; The individual reads of a and b are atomic, and all writes elsewhere in the code to these two memory locations are also loc...

How to perform atomic 64b read on x86 (Pentium and above)?

I would like to perform and atomic read of 64b aligned 64b data on x86 platform (Pentium or above guaranteed). Is there a way to do this? (And no, I do not want to use a critical section or a mutex for this, I want this to be lock-free). ...

Better way to implement a generic atomic load or store in GCC?

I am aware of GCC's builtin atomic operations: http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Atomic-Builtins.html But this list doesn't include very simple operations like load and store. I could implement these on limited architectures with inline assembly (in fact for many like x86 they will be basically just regular mov's), but is ther...

Atomic modification of files across multiple networks

I have an application that is modifying 5 identical xml files, each located on a different network share. I am aware that this is needlessly redundant, but "it must be so." Every time this application runs, exactly one element (no more, no less) will be added/removed/modified. Initially, the application opens each xml file, adds/remov...

How to make a macro "atomic"

IOW how do I make OOo's undo/redo work properly when a macro is executed? This is related to my previous question: #853176 ...

C++ atomic operations for lock-free structures

I'm implementing a lock-free mechanism using atomic (double) compare and swap instructions e.g. cmpxchg16b I'm currently writing this in assembly and then linking it in. However, I wondered if there was a way of getting the compiler to do this for me automatically? e.g. surround code block with 'atomically' and have it go figure it out...

interlocked operation on unanligned data

Hi; The win32 interlocked functions provide a mecanism for atomic operation on data. They are supposed to be thread-safe and multiprocessor-safe. What happen if the data is not aligned? the interlocked operations are still atomic? Ex.: incrementing a integer that is not aligned. Ty ...

Thread safety... what's my "best" course of action?

I'm wondering what is the "best" way to make data thread-safe. Specifically, I need to protect a linked-list across multiple threads -- one thread might try to read from it while another thread adds/removes data from it, or even frees the entire list. I've been reading about locks; they seem to be the most commonly used approach, but ap...

Does one assembler instruction always execute atomically?

Today I came across this question: you have a code static int counter = 0; void worker() { for (int i = 1; i <= 10; i++) counter++; } If worker would be called from two different threads, what value will counter have after both of them are finished? I know that actually it could be anything. But my internal guts tells me...

MS Access Atomic Transactions

Is there any way to make microsoft access transactions atomic across multiple users? I have found this which seems to imply that they are not, but I am wondering if atomicity in access is driver specific. ...

UNIX Portable Atomic Operations

Is there a (POSIX-)portable way in C for atomic variable operations similar to a portable threading with pthread? Atomic operations are operations like "increment and get" that are executed atomically that means that no context switch can interfere with the operation. In Linux kernel space, we have to atomic_t type, in Java we have the ...