atomicity

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

与世无争的帅哥 提交于 2019-11-26 14:16:09
In my multithreaded asmx web service I had a class field _allData of my own type SystemData which consists of few List<T> and Dictionary<T> marked as volatile . The system data ( _allData ) is refreshed once in a while and I do it by creating another object called newData and fill it's data structures with new data. When it's done I just assign private static volatile SystemData _allData public static bool LoadAllSystemData() { SystemData newData = new SystemData(); /* fill newData with up-to-date data*/ ... _allData = newData. } This should work since the assignment is atomic and the threads

When do I really need to use atomic<bool> instead of bool? [duplicate]

百般思念 提交于 2019-11-26 12:54:57
问题 This question already has an answer here: Can a bool read/write operation be not atomic on x86? [duplicate] 3 answers Do I have to use atomic<bool> for “exit” bool variable? 3 answers Isn\'t atomic<bool> redundant because bool is atomic by nature? I don\'t think it\'s possible to have a partially modified bool value. When do I really need to use atomic<bool> instead of bool ? 回答1: No type in C++ is "atomic by nature" unless it is an std::atomic* -something. That's because the standard says so

Is rename() atomic?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:10:51
问题 I am not being able to check this via experiments and could not gather it from the man pages as well. Say I have two processes, one moving(rename) file1 from directory1 to directory2. Say the other process running concurrently copies the contents of directory1 and directory2 to another location. Is it possible that the copy happens in such a way that both directory1 and directory2 will show file1 - i.e directory1 is copied before the move and directory2 after the move by the first process.

should LOCK_EX on both read & write be atomic?

試著忘記壹切 提交于 2019-11-26 11:08:22
问题 file_put_contents ( \"file\", \"data\", LOCK_EX ) for writing (which means - aquire lock and write) file_get_contents ( \"file\", LOCK_EX ) for reading (which means - aquire lock and then read) will it throw exception? raise an error? block until lock is aquired? or at least - should it ? is there a chance that php will behave like this one day? EDIT: i know that it is possible to use rename - i\'d like to know answer to this... 回答1: Since this answer is long, here's the summary: No, file_get

What operations in Java are considered atomic?

若如初见. 提交于 2019-11-26 03:50:44
What operations in Java are considered atomic? all assignments of primitive types except for long and double all assignments of references all assignments of volatile variables all operations of java.concurrent.Atomic* classes and maybe something more. Look at the jls . As noted in the comments, atomicity does not imply visibility. So while another thread is guaranteed not to see a partially written int , it may never see the new value. The operations on long and double are on common 64 bit CPUs atomic as well , although there's no guarantee. See also this feature request . In Java, the

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

筅森魡賤 提交于 2019-11-26 03:49:38
问题 In my multithreaded asmx web service I had a class field _allData of my own type SystemData which consists of few List<T> and Dictionary<T> marked as volatile . The system data ( _allData ) is refreshed once in a while and I do it by creating another object called newData and fill it\'s data structures with new data. When it\'s done I just assign private static volatile SystemData _allData public static bool LoadAllSystemData() { SystemData newData = new SystemData(); /* fill newData with up

What operations in Java are considered atomic?

送分小仙女□ 提交于 2019-11-26 01:14:29
问题 What operations in Java are considered atomic? 回答1: all assignments of primitive types except for long and double all assignments of references all assignments of volatile variables all operations of java.concurrent.Atomic* classes and maybe something more. Look at the jls. As noted in the comments, atomicity does not imply visibility. So while another thread is guaranteed not to see a partially written int , it may never see the new value. The operations on long and double are on common 64

Is file append atomic in UNIX?

自闭症网瘾萝莉.ら 提交于 2019-11-26 01:06:28
问题 In general, what can we take for granted when we append to a file in UNIX from multiple processes? Is it possible to lose data (one process overwriting the other\'s changes)? Is it possible for data to get mangled? (For example, each process is appending one line per append to a log file, is it possible that two lines get mangled?) If the append is not atomic in the above sense, then what\'s the best way of ensuring mutual exclusion? 回答1: A write that's under the size of 'PIPE_BUF' is

Is file append atomic in UNIX?

为君一笑 提交于 2019-11-26 00:40:09
In general, what can we take for granted when we append to a file in UNIX from multiple processes? Is it possible to lose data (one process overwriting the other's changes)? Is it possible for data to get mangled? (For example, each process is appending one line per append to a log file, is it possible that two lines get mangled?) If the append is not atomic in the above sense, then what's the best way of ensuring mutual exclusion? freiheit A write that's under the size of 'PIPE_BUF' is supposed to be atomic. That should be at least 512 bytes, though it could easily be larger (linux seems to