synchronization

Needed clarifications for NSFetchedResultsController and NSFetchedResultsControllerDelegate

可紊 提交于 2019-12-07 03:27:23
Within SO there are a lot of questions/replies about NSFetchedResultsController and delegate. Sometimes the delegate fires, sometimes not. And since Core Data is quite complex argument is quite difficult to understand what is going on without spending a lot of time on it. In addition, the documentations says that there are several problems but it does not list them. There are several known issues and behavior changes with NSFetchedResultsController on various releases of iOS. Hence, I need some clarifications about the behavior of such a class. In particular, from the documentation there is

strict N process synchronization using 2 semaphores

99封情书 提交于 2019-12-07 03:12:27
a few years ago I had an Operating Systems seminar. I had been tasked to create an algorithm for process synchronization using as few semaphores as possible. It should have looked like this: P1 -> P2 -> P3 -> P4 -> P5 P(n) - process Only one process running at a time and strict ordering was needed . Last year I came with solution using 3 semaphores (effectively creating a barrier). Here is my algorithm: P S1 S1 S1 S1 4W1 W0 W0 W0 W0 4S0 P S2 S2 S2 3W2 W1 W1 W1 3S1 P S1 S1 2W1 W0 W0 2S0 P S2 W2 W1 S1 P (execution is from top to bottom, each lane is a single process) P - real work which needs to

Other way to synchronize method

末鹿安然 提交于 2019-12-07 00:05:47
问题 How to synchronize method in java other than using synchronized keyword? 回答1: You could use the java.util.concurrent.locks package, especially Lock interface: Lock l = ...; l.lock(); try { // access the resource protected by this lock } finally { l.unlock(); } See here. 回答2: Depends on you concrete needs. See Java concurrent package for higher level synchronization abstractions. Note that they may still use synchronized underneath ... 回答3: you can use Lock classes provided in java.util

How is class level locking achieved in java?

断了今生、忘了曾经 提交于 2019-12-06 23:38:59
I am aware of locking concepts with synchronization of static and non static methods to lock classes and instances respectively. What I am not able to understand is, how is class level lock achieved? I mean, class is a template only, with no physical significance. So, when we say that class level locking is achieved with synchronizing static methods what happens then? Do all the objects of that class get locked or some other process? With what I could find out with my search is that there are class objects (Class.class) and lock is acquired on this class object. But then how are all instances

How does the piggybacking of current thread variable in ReentrantLock.Sync work?

心已入冬 提交于 2019-12-06 22:32:32
问题 I read about some of the details of implementation of ReentrantLock in "Java Concurrency in Practice", section 14.6.1, and something in the annotation makes me confused: Because the protected state-manipulation methods have the memory semantics of a volatile read or write and ReentrantLock is careful to read the owner field only after calling getState and write it only before calling setState , ReentrantLock can piggyback on the memory semantics of the synchronization state, and thus avoid

Java synchronized block vs concurrentHashMap vs Collections.synchronizedMap

99封情书 提交于 2019-12-06 22:24:39
问题 Say If have a synchronized method and within that method, I update a hashmap like this: public synchronized void method1() { myHashMap.clear(); //populate the hashmap, takes about 5 seconds. } now while the method1 is running and the hashmap is being re-populated, if there are other threads tring to get the value of the hashmap, I assume they will get blocked? Now instead of using sync method, if I change hashmap to ConcurrentHashMap like below, what's the behaviour? public void method1() {

Check if adjacent slave process is ended in MPI

▼魔方 西西 提交于 2019-12-06 21:38:27
In my MPI program, I want to send and receive information to adjacent processes. But if a process ends and doesn't send anything, its neighbors will wait forever. How can I resolve this issue? Here is what I am trying to do: if (rank == 0) { // don't do anything until all slaves are done } else { while (condition) { // send info to rank-1 and rank+1 // if can receive info from rank-1, receive it, store received info locally // if cannot receive info from rank-1, use locally stored info // do the same for process rank+1 // MPI_Barrier(slaves); (wait for other slaves to finish this iteration) }

Is the Win32 registry thread-safe?

戏子无情 提交于 2019-12-06 17:11:53
问题 If I have two processes accessing a given registry key (e.g. HKLM ), should I wrap the the logic in a mutex? 回答1: The registry will make sure the actions are atomic, so you don't have to synchronize it yourself. However, if you have multiple processes / threads accessing the registry at the same time, it doesn't make any guarantees about which happens first. Only that you won't get garbled data. Edit: Further reading, see The inability to lock someone out of the registry is a feature, not a

Waiting for condition in Java

巧了我就是萌 提交于 2019-12-06 16:00:10
问题 I want to make one thread that puts values to a queue when it gets empty and wait for this condition while it is not. Here's the code I've tried to use, but it prints Adding new Taking Value 1 Taking Value 2 Taking Value 3 Taking Value 4 So it is working only one time. What is the problem? import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class SO { public String test; public String[] list = new String[] {test}; public static void main(String[]

Deadlock when synchronizing two simple python3 scripts using 0mq (ZeroMQ)

时光怂恿深爱的人放手 提交于 2019-12-06 15:44:17
I get this strange deadlock when I try to synchronize two python3 scripts using 0mq ( ZeroMQ ). The scripts run fine for several thousand iterations, but sooner or later they both stop and wait for each other. I am running both scripts from different CMD-Windows on Windows 7. I cannot figure out why such a deadlock is even possible . What can go wrong here? Script A: while (1): context = zmq.Context() socket = context.socket(zmq.REP) socket.bind('tcp://127.0.0.1:10001') msg = socket.recv() # Waiting for script B to send done # ...................................................................