atomicity

C++ if one thread writes toggles a bool once done, is it safe to read that bool in a loop in a single other thread?

纵饮孤独 提交于 2021-02-16 08:57:15
问题 I am building a very simple program as an exercise. The idea is to compute the total size of a directory by recursively iterating over all its contents, and summing the sizes of all files contained in the directory (and its subdirectories). To show to a user that the program is still working, this computation is performed on another thread, while the main thread prints a dot . once every second. Now the main thread of course needs to know when it should stop printing dots and can look up a

What happens when a hive insert is failed halfway?

岁酱吖の 提交于 2021-02-15 03:13:21
问题 Suppose an insert is expected to load 100 records in hive and 40 records have been inserted and the insert failed for some reason. will the transaction roll back completely, undoing 40 records which were inserted? or Will we see 40 records in the hive table even after the insert query failed? 回答1: The operation is atomic (even for non-ACID table): If you inserting or rewriting data using HiveQL, it writes data into temporary location and only if the command succeeds files are moved to the

What happens when a hive insert is failed halfway?

给你一囗甜甜゛ 提交于 2021-02-15 03:13:20
问题 Suppose an insert is expected to load 100 records in hive and 40 records have been inserted and the insert failed for some reason. will the transaction roll back completely, undoing 40 records which were inserted? or Will we see 40 records in the hive table even after the insert query failed? 回答1: The operation is atomic (even for non-ACID table): If you inserting or rewriting data using HiveQL, it writes data into temporary location and only if the command succeeds files are moved to the

Atomic compare, Multi-Processor, C/C++ (Linux)

随声附和 提交于 2021-02-07 09:02:31
问题 I have a variable in shared memory x on a multi- processor system. void MyFunction(volatile int* x) { if (*x != 0) { // do something } } Other processes (possibly on different processors) will be writing to x using gcc built-in atomic operations such as __sync_bool_compare_and_swap etc. I think I'm running into some cache concurrency issues where sometimes it takes a bit of time before x finally gets updated with the new value. What I want is a kind of atomic_compare (without the swap), if

Refactoring synchronization blocks keeping ordering of execution intact

落爺英雄遲暮 提交于 2021-01-29 10:29:32
问题 I have this synchronized block in one of my classes, whose main responsibility is to capture metrics around service calls. All variables prefixed with _ are class variables and are primitive longs. I am looking to refactor this synchronized block so as to increase the throughput, but keeping the overall accuracy intact. I have a test setup which calls this method from Runnable threads using an executor service. I am doing a comparison on the metrics before and after refactoring. public

On x86-64, is the “movnti” instruction atomic?

亡梦爱人 提交于 2021-01-27 13:20:15
问题 On x86-64 CPUs (either Intel or AMD), is the "movnti" instruction that writes 4/8 bytes to a 32/64-bit aligned address atomic? 回答1: Yes, movnti is atomic on naturally-aligned addresses, just like all other naturally-aligned 8/16/32/64b stores (and loads) on x86. This applies regardless of memory-type (writeback, write-combining, uncacheable, etc.) See that link for the wording of the guarantees in Intel's x86 manual. Note that atomicity is separate from memory ordering. Normal x86 stores are

Is clflush or clflushopt atomic when system crash?

有些话、适合烂在心里 提交于 2021-01-27 05:27:33
问题 Commonly, cacheline is 64B but atomicity of non-volatile memory is 8B. For example: x[1]=100; x[2]=100; clflush(x); x is cacheline aligned, and is initially set to 0 . System crashs in clflush(); Is it possible x[1]=0 , x[2]=100 after reboot? 回答1: Under the following assumptions: I assume that the code you've shown represents a sequence of x86 assembly instructions rather than actual C code that is yet to be compiled. I also assume that the code is being executed on a Cascade Lake processor

Atomic exchange of two std::atomic<T*> objects in a lock-free manner in C++11?

帅比萌擦擦* 提交于 2020-08-24 06:09:30
问题 The following code is a skeleton of an atomic pointer class taken from a simulated annealing application in the PARSEC benchmark suite for shared-memory multiprocessors. In that application, the central data structure is a graph (more specifically, a netlist of an integrated circuit). Each node in the graph has an attribute indicating its physical location. The algorithm spawns many threads and each thread repeatedly and randomly selects two nodes and exchanges their physical locations if

Can an atomic release be “overwritten”?

最后都变了- 提交于 2020-08-05 07:31:31
问题 Say I have atomic<int> i; Thread A performs an atomic store/exchange with memory_order_release. Next, Thread B performs an atomic store with memory_order_release. Thread C performs an atomic fetch_add(0, memory_order_acquire); Does Thread C acquire dependencies from thread A and B or only thread B ? 回答1: Only B (I'm going to assume that by "next" you mean the modification order of the atomic is A -> B -> C so that by [atomics.order]p11 C 's RMW must read the value B wrote). See the note in