synchronization

synchronization across multiple processes in python

坚强是说给别人听的谎言 提交于 2019-12-04 14:14:39
I have a python application that spawns a separate process to do some work (I ran into performance issues using threads due to the GIL (global interpreter lock)). Now what's my methods in python to synchronize shared resources across processes? I move data into a queue and a spawn process does the work when as it receives data from that queue. But I need to be able to guarantee that the data is coming out in an orderly fashion, same order as it was copied in so I need to guarantee that only one process at any time can read/write from/to the queue. How do I do that best? Thanks, Ron I think you

Implementation of synchronization primitives over HTML5 local storage

99封情书 提交于 2019-12-04 14:02:45
Consider a scenario where a browser has two or more tabs pointing to the same origin. Different event loops of the different tabs can lead to race conditions while accessing local storage and the different tabs can potentially overwrite each other's changes in local storage. I'm writing a web application that would face such race conditions, and so I wanted to know about the different synchronization primitives that could be employed in such a scenario. My reading of the relevant W3C spec , and the comment from Ian Hickson at the end of this blog post on the topic , suggests that what's

Android: Enable/Disable Auto Sync and Background Data

筅森魡賤 提交于 2019-12-04 13:40:45
I want to develop an application that disables the Background Data (new feature in Android 1.5) and Auto Sync and then enables GPRS/EDGE connection and vice versa. I figured out how to enable/disable GPRS/EDGE by changing the APN settings. (weird solution. However; Android developers couldn't think a user may want to disable GPRS/EDGE) But, I couldn't find a way to enable/disable Auto Sync and Background data. I investigated the Android code and as I understood, the Sync operation is an intent. So, I wanted to reach with putExtra to the intent and trigger the enabling/disabling. But; I couldn

Core Data iCloud Syncing

佐手、 提交于 2019-12-04 13:06:06
I have implemented Core Data as local storage for a new app and now want to enable iCloud synchronising across devices. I've been reading the documentation and some tutorials but can't get my head around how to switch between local and cloud storage, and how to synchronise changes from iCloud when cloud storage is enabled. Would somebody mind summarising the process so I can then go and research each stage? Thanks in advance! I've managed to get this working by following this tutorial: http://corsarus.com/2015/using-core-data-in-ios-part-4-core-data-syncing-with-icloud/ To summarise the

Can multiple CPUs simultaneously write to the same RAM location?

社会主义新天地 提交于 2019-12-04 12:56:23
Are machine word size (or smaller) writes serialized? Only one native opcode is needed to copy register content to RAM. Writing data to RAM is atomic. If two CPUs try to write to the same location at the same time, the memory controller will decide on some order for the writes. While one CPU is writing to memory, the other CPU will stall for as many cycles as necessary until the first write is completed; then it will overwrite its value. This is what's known as a race condition . Writes that are smaller than the native word size are not atomic -- in that case, the CPU must read the old memory

Spurious wakeups, wait() and notifyAll()

泄露秘密 提交于 2019-12-04 12:51:35
I have N threads that do these things in loop: increase shared variable, checks if shared variable value is N (if so put value to queue) and do wait(). I have one more threat that checks the q variable. If queue is true, it does notifyAll(). After that N threads should wake up, and do another run of loop. But it seems that some threads are waking up without notification. I've read about spurious wakeups, but I don't know what condition should I put to while() to check if it was spurious wake up. Bellow is example of my code (not the same, but very similar in meaning): Shared class is shared

Ruby synchronisation: How to make threads work one after another in proper order?

坚强是说给别人听的谎言 提交于 2019-12-04 11:58:28
My problem is that I don't know how synchronise multiple threads using Ruby. The task is to create six threads and start them immediately. All of them should do some work (for example puts "Thread 1" Hi" ) one after another in the order I need it to work. I've tried to work with Mutex, Monitor and Condition Variable, but all of them worked in random order. Could anybody explain how to achieve my goal? After some time of struggling with Mutex and Condition Variable I've achieved my goal. This code is a little bit messy, and I intentionally did't use cycles for "clearer view". cv =

Two generals' agreement

旧城冷巷雨未停 提交于 2019-12-04 11:57:52
I am trying to figure an agreement protocol on an unreliable channel. Basically two parties (A and B) have to agree to do something, so it's the two generals' problem . Since there is no bullet-proof solution, I am trying to do this. A continuously sends a message with sequence 1 When B receives seq 1 it continuously replies with sequence 2 At this point A receives seq 2 so it starts sending seq 3 ... My question. When can the two parties conclude that they can take the action ? Obviously I can't set a condition: " do it after receiving 10 messages " since the last sender won't have any

Does synchronized park a concurrent thread like Lock.lock() does?

浪子不回头ぞ 提交于 2019-12-04 11:45:06
When we call either lock.lock() or try to enter a synchronized block then our thread blocks if some other thread has already taken that lock. Now my question is, when we look at the implementation of lock.lock() it delegates acquiring lock to AQS which actually parks the current thread (so that it cannot be scheduled further by scheduler). Is it the same case with synchronized blocking also? I even think my thread status are also different. For example, if my thread is blocked on synchronized block it will be BLOCKING while if I have called lock.lock() , then it will be WAITING . Am I right?

Is it safe to access VT data from the other thread?

允我心安 提交于 2019-12-04 11:06:01
Is it safe to change VirtualTreeView data from the secondary thread ? And if yes, should I use critical sections (or even Synchronize method) ? I'm afraid that when I'll be writing to the VT's data record from the other thread, main thread invokes its repaint meanwhile and this refresh will cause reading of the same record at one time. I would supplement I'm using only 2 threads in the application. Something like ... type PSomeRecord = ^TSomeRecord; TSomeRecord = record SomeString: string; SomeInteger: integer; SomeBoolean: boolean; end; ... var FCriticalSection: TRTLCriticalSection; // global