Among the atomic operations provided by BSD (as given on the atomic(9) man page), there are atomic_load_acq_int() and atomic_store_rel_int(). In looking for the equivalent for other OSs (for example, by reading the atomic(3) man page for Mac OS X, the atomic_ops(3C) man page for Solaris, and the Interlocked*() functions for Windows), th...
I know how to atomically write a value in x86 ASM. But how do I read one? The LOCK prefix can't be used with mov.
To increase a value, I am doing:
lock inc dword ptr Counter
How do I read Counter in a thread-safe way?
...
I wish to setup a database table that will be used as a message queue. The table will have messages inserted into it with a unique id and a timestamp and a status of 'PENDING'.
Assuming that the insertion into this table is properly handled, I wish to know what is the best way to transactionally process messages from this table using a ...
Is correct to divide the following statements:
int v = ++j;
as:
read j value (atomic);
increment by 1 the value read (NON
atomic possibly interference by
other thread);
write the adding result to i
(atomic);
write i into v (atomic)
...
I'm experimenting Java Multi-Threading using synchronization on method comparing with Atomic variables (java.util.concurrent.atomic package).
Below are the classes:
// Interface ICounter.java
public interface ICounter {
public void increment();
public void decrement();
public int value();
...
What is the best approach to achieve thread-safety for rather simple operations?
Consider a pair of functions:
void setVal(int val)
{
this->_val = val;
}
int getVal() {
return this->_val;
}
Since even assignments of primitive types aren't guaranteed to be atomic, should I modify every getter and setter in the program in th...
Is it necessary to use a temporary here to be thread-safe?
int getVal() {
this->_mutex.lock();
int result = this->_val;
this->_mutex.unlock();
return result;
}
I'll give you disassembly of simple RAII test function
int test()
{
RAIITest raii; //let's say it's a scoped lock
return 3;
}
{
0...
I would like to put two objects into a queue, but I've got to be sure the objects are in both queues at the same time, therefore it should not be interrupted in between - something like an atomic block. Does some one have a solution? Many thanks...
queue_01.put(car)
queue_02.put(bike)
...
Suppose I am processing a large amount of incoming data from multiple threads. I may want for this data to act as a trigger for a specific action when certain criteria are met. However, the action is not reentrant; so the same trigger being fired twice in rapid succession should only cause the action to run once.
Using a simple bool fla...
Hello!
I've recently read section 5.5.2 (Spinlocks and Atomic Context) of LDDv3 book:
Avoiding sleep while holding a lock can be more difficult; many kernel functions can sleep, and this behavior is not always well documented. Copying data to or from user space is an obvious example: the required user-space page may need to be swapp...
Reading this question, I wanted to test if I could demonstrate the non-atomicity of reads and writes on a type for which the atomicity of such operations is not guaranteed.
private static double _d;
[STAThread]
static void Main()
{
new Thread(KeepMutating).Start();
KeepReading();
}
private static void KeepReading()
{
whil...
Hi,
I am wondering whether python's shutil.move is atomic on linux ? Is the behavior different if the source and destination files are on two different partitions or is it same as when they are present on the same partition ?
I am more concerned to know whether the shutil.move is atomic if the source and destination files are on the sa...
I'm attempting to implement the atomic library from the C++0x draft. Specifically, I'm implementing §29.6/8, the store method:
template <typename T>
void atomic<T>::store(T pDesired, memory_order pOrder = memory_order_seq_cst);
The requirement states:
The order argument shall not be memory_order_consume, memory_order_acquire, nor...
If I read and write a single file using normal IO APIs, writes are guaranteed to be atomic on a per-block basis. That is, if my write only modifies a single block, the operating system guarantees that either the whole block is written, or nothing at all.
How do I achieve the same effect on a memory mapped file?
Memory mapped files are ...
Hi, I'm trying to figure out how if rsyncing files is atomic. I couldn't find any confirmation about it. Due to rsync being able to send only deltas, I was under the impression that it also updates only parts of the live files.
On the other hang DJB recommends rsync for synchronising live .cdb files and I've found this post ( http://lis...
The atomic directive in openmp supports stuff like
x += expr
x *= expr
where expr is an expression of scalar type that does not reference x. I get that, but I don't get why you can't do:
#pragma omp atomic
x = y;
Is this somehow more taxing cpu instruction-wise? Seems to me that both the legal and illegal statement loads the value ...
I have to make a sequence of method calls in C# such that, if one of them fails, the subsequent methods should not be called. In short, the set of calls should be made atomic. How do I achieve this in C#?
...
I have a question about SQL and locking strategies. As an example, suppose I have a view counter for the images on my website. If I have a sproc or similar to perform the following statements:
START TRANSACTION;
UPDATE images SET counter=counter+1 WHERE image_id=some_parameter;
COMMIT;
Assume that the counter for a specific image_id h...
In the following code:
a = Interlocked.Exchange(ref b, c);
I know b is set to c atomically. But is a also set to b in the same atomic operation? Or is this outside of the atomic operation.
What I need is to ensure both a and b are set in the same atomic operation.
c => b, b => a
This is in C#.Net.
...
What (if any) is the C# equivalent of the ASM command "XCHG".
With that command, which imo is a genuine exchange (unlike Interlocked.Exchange), I could simply atomically swap two ints, which is what I am really trying to do.
...