atomicity

Is iinc atomic in Java?

倖福魔咒の 提交于 2019-12-18 12:29:43
问题 I know increment operation is not atomic in C++ without locking. Will JVM add any lock on its implementation of iinc instruction? 回答1: No its not Retrieve the current value of c. Increment the retrieved value by 1. Store the incremented value back in c. Java Documentation for Atomicity and Thread Interference You need to either use synchronized keyword or use AtomicXXX methods for Thread safety. UPDATE : public synchronized void increment() { c++; } or AtomicInteger integer = new

Is pointer assignment atomic in C++?

和自甴很熟 提交于 2019-12-18 05:43:39
问题 I've actually heard claims both ways. I suspect they are not, but I wanted to get the topic settled. 回答1: C++03 does not know about the existance of threads, therefore the concept of atomicity doesn't make much sense for C++03, meaning that it doesn't say anything about that. C++11 does know about threads, but once again doesn't say anything about the atomicity of assigning pointers. However C++11 does contain std::atomic<T*> , which is guaranteed to be atomic. Note that even if writing to a

Atomic properties vs thread-safe in Objective-C

六眼飞鱼酱① 提交于 2019-12-17 17:44:07
问题 In most of the discussions I've read, it indicates that making a property atomic does not guarantee it to be thread-safe, it just guarantees that the value returned won't be garbage as a result of one object writing to it and another trying to read it at the same time. I understand this isn't thread-safe as a third object could be writing it and while the object accessing it wouldn't get garbage back, it's not entirely certain which value it will get back as multiple objects are writing to it

Linux Kernel module Atomic mode

[亡魂溺海] 提交于 2019-12-13 04:16:00
问题 I am developing linux kernel module to perform read/write operations. It reads an input file and write the content to an output file. I have to introduce atomic mode to my code. I wanted to know if there is a way to revert changes from a written file in case of partial write for atomic mode. I want to delete all content I have written to an output file in case my programs gives an error. Please reply. 回答1: I want to delete all content I have written to an output file in case my programs gives

c++ std::atomic<bool>::fetch_or not implemented?

橙三吉。 提交于 2019-12-12 16:19:52
问题 With this excerpt of code: class myclass { volatile std::atomic<bool> flag; public: myclass(): flag(false) {} bool get_flag() { return flag; } bool try_set() { return !flag.fetch_or(flag, true); } void reset() { flag = false; } }; I am having this compile error: error: ‘volatile struct std::atomic<bool>’ has no member named ‘fetch_or’ return !flag.fetch_or(flag, true); It compiles if, however, I change the template parameter to int : class myclass { volatile std::atomic<int> flag; public:

Is mkdir still atomic? (Windows 7 filesystems mounted on SAN)

試著忘記壹切 提交于 2019-12-12 10:50:01
问题 We have some old applications that communicate via directory-based queues. Each item in the queue is a file, and there's a header file that maintains an ordered list of the filenames for the items in the queue. Naturally, this old code needs to lock the queue while items are pushed and popped. What it's doing is creating a lock subdirectory, on the assumption that mkdir() is an atomic operation - if multiple processes attempt to create a directory, only one of them is going to succeed. One of

What happens if I log into the same file from multiple different processes in python?

女生的网名这么多〃 提交于 2019-12-12 08:06:08
问题 I spent hours to dig the behavior, first about those questions: Atomicity of `write(2)` to a local filesystem How can I synchronize -- make atomic -- writes on one file from from two processes? How does one programmatically determine if "write" system call is atomic on a particular file? What happens if a write system call is called on same file by 2 different processes simultaneously http://article.gmane.org/gmane.linux.kernel/43445 It seems if we use 'O_APPEND' flag when opening file, it

Shared enum between multiple threads

佐手、 提交于 2019-12-12 04:49:22
问题 I have an enumeration that is shared between multiple threads: public enum Action { Read, Write, None } Within a class I have a variable of Action type: public Action _action; This is a shared variable, that is, it is updated and read from multiple threads. For example, from one thread I do: _action = Action.Read And from another one: if (_action == Action.Read) { } else if (_action == Action.Write) { } else if (_Action == Action.None) { } else { } So I would like to use Interlock to update

When to use Firebase transactions or not

血红的双手。 提交于 2019-12-12 04:33:13
问题 Is it necessary to use the Save data as transactions Technic if a value only increases?. In the example Firebase doc social blogging app the starCount can go upp or down so it´s logical to use the Transaction Technic right. But if value only increases I suppose the Transaction Technic is not needed right? or? Multiple users at the same time increasing a value right. 回答1: The counter can grow up or down, means that a user can click on the counter to increase the value, but can also decrease

addition on std::atomic<double> not adding up to non-atomic counterpart

微笑、不失礼 提交于 2019-12-12 04:33:00
问题 I am trying to perform an addition on a double atomically in a loop using a compare and exchange scheme with this function: namespace my { template<typename value_type> value_type atomic_add(std::atomic<value_type>& operand, value_type value_to_add) { value_type old = operand.load(std::memory_order_consume); value_type desired = old + value_to_add; while (!operand.compare_exchange_weak(old, desired, std::memory_order_release, std::memory_order_consume)) desired = old + value_to_add; return