atomicity

python - ensure script is activated only once

隐身守侯 提交于 2019-12-06 01:39:35
问题 I'm writing a Python 2.7 script. In summary, this script is being run every night on Linux and activates several processes. I'd like to ensure this script is not run multiple times in parallel (basically trying to mimic Singleton pattern but on application level) . Code Example def main(): # before doing anything, I'd like to know whether this # script was activated and alive. # if so, error out # do something if __name__ == "__main__": main() Suggestion The naive solution would be to create

Atomic counters in Spring with Couchbase

蹲街弑〆低调 提交于 2019-12-06 00:20:25
Is it possible to use Couchbase's Atomic Counters with the Spring Connector? Currently I have a repository for a specific document type and want to have an atomic counter for every document. I know that the Java SDK offers the functionality but I was not able to find an equivalent action for Spring. As I know Spring doesn't have support for counters but it's pretty simple to write own repository: @Repository public class CountersRepository { private static final long INITIAL_COUNTER_VALUE = 1; @Autowired private Bucket bucket; public void incCounter(final String counter) { bucket.counter

File.Move atomic operation [duplicate]

萝らか妹 提交于 2019-12-05 21:58:30
问题 This question already has answers here : Atomicity of File.Move (1 answer) Atomic file copy under .NET (4 answers) Closed 6 years ago . I am trying to generate a huge text file using C# and another process is constantly looking at the location and trying to pickup the file if available. In order to make the file atomic below are the steps : 1 - Write to file : Filename_temp.txt 2 - Check if Filename.txt already exists then Delete 3 - Do a File.Move to the same destination From filename :

What is atomic?

老子叫甜甜 提交于 2019-12-05 19:25:34
These are two atomic operations: int value = 5; Object obj = new Object(); But when using a primitive as a method parameter, would this be considered as an atomic operation: public void setValue(int val, Object obj){ this.value = val; // Atomic? this.obj = obj; // Not atomic? } ? The copy of the object reference is not atomic since it includes a read and a write, right? Would it be correct to say that the only way to make an atomic operation on an object reference is to declare it null or assign a new object to it, like: Object obj = null; and Object obj = new Object(); ? If the parameter in

MySQL command line and transactions

北慕城南 提交于 2019-12-05 07:28:25
I have a question about MySQL and have been unable to find an answer. I know auto-commit is turned on by default in MySQL. I need to run a few update queries from the command line in one transaction but I don't know how MySQL will handle them. If I have something like this: mysql -uroot -proot -e 'QUERY 1; QUERY 2; QUERY3' will it execute as one transaction or will MySQL auto-commit each statement individually? I need to ensure atomicity. You can use MySQL's START TRANSACTION syntax to create a transactional commit: Source: http://dev.mysql.com/doc/refman/5.0/en/commit.html START TRANSACTION;

Atomic read and write of long and double values

 ̄綄美尐妖づ 提交于 2019-12-05 05:13:39
long and double read and write operation are not atomic because of their size more than cpu word size. So could I get atomic read and write operation of long and double if I have 64 bit machine? so could i get atomic read and write operation of long and double if i have 64 bit machine ? The answer is "maybe". The answer depends on the JVM implementation as well as the machine architecture. To quote from the Java Language definition 17.7 : Some implementations may find it convenient to divide a single write action on a 64-bit long or double value into two write actions on adjacent 32-bit values

Pop multiple values from Redis data structure atomically?

徘徊边缘 提交于 2019-12-04 22:15:30
Is there a Redis data structure, which would allow atomic operation of popping (get+remove) multiple elements, which it contains? There are well known SPOP or RPOP, but they always return a single value. Therefore, when I need first N values from set/list, I need to call the command N-times, which is expensive. Let's say the set/list contains millions of items. Is there anything like SPOPM "setName" 1000 , which would return and remove 1000 random items from set or RPOPM "listName" 1000 , which would return 1000 right-most items from list? I know there are commands like SRANDMEMBER and LRANGE,

Atomic state storage in Python?

纵然是瞬间 提交于 2019-12-04 21:32:18
I'm working on a project on an unreliable system which I'm assuming can fail at any point. What I want to guarantee is that if I write_state and the machine fails mid-operation, a read_state will either read a valid state or no state at all. I've implemented something which I think will work below -- I'm interested in criticism of that or alternative solutions if anyone knows of one. My idea: import hashlib, cPickle, os def write_state(logname, state): state_string = cPickle.dumps(state, cPickle.HIGHEST_PROTOCOL) state_string += hashlib.sha224(state_string).hexdigest() handle = open('%s.1' %

How to compare and swap atomically in ARM7?

回眸只為那壹抹淺笑 提交于 2019-12-04 19:23:42
I would like to modify a global variable which is shared by different tasks and IRQ contexts in a RTOS. Therefore I need to modify this variable atomically. In my current implementation, I have been using enable_irq/disable_irq functions to modify the statement atomically. extern int g_var; void set_bit_atomic(int mask) { disable_irq(); g_var |= mask; enable_irq(); } I've found the __sync_bool_compare_and_swap function in GCC documentation as a helper for atomic operations. My current toolchain is KEIL MDK, and I would like to switch to the approach shown below, void set_bit_atomic(int mask) {

What means “atomic” system call?

不羁的心 提交于 2019-12-04 16:53:38
I know that atomic is usually used in the context of race condition and means something like consistency and determinism of the result according to multithreading/multiprocessing environment . That's ok. But recently I read about atomic system calls in Linux and didn't understand what does atomic actually mean here, i.e. how this atomicity is implemented . Does it mean that this system calls simply use locks on the resources (e.g. open() on the target file inode) or there is anything more, may be some kernel guarantees? I think about disabling interrupts but not all interrupts can be disabled.