Questions tagged [synchronization]

Synchronization refers to using controls to maintain a coherent representation, either a group of processes running the same program (process synchronization), or representations of data (data synchronization).

In computer science, synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, so as to reach an agreement or commit to a certain sequence of action. Data synchronization refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. Process synchronization primitives are commonly used to implement data synchronization.

-from Synchronization (computer science) - Wikipedia

12446 questions
4643
votes
31 answers

How do I update or sync a forked repository on GitHub?

I forked a project, made changes, and created a pull request which was accepted. New commits were later added to the repository. How do I get those commits into my fork?
Lea Hayes
  • 62,536
  • 16
  • 62
  • 111
635
votes
9 answers

What does a lock statement do under the hood?

I see that for using objects which are not thread safe we wrap the code with a lock like this: private static readonly Object obj = new Object(); lock (obj) { // thread unsafe code } So, what happens when multiple threads access the same code…
NLV
  • 21,141
  • 40
  • 118
  • 183
487
votes
9 answers

Why can't I use the 'await' operator within the body of a lock statement?

The await keyword in C# (.NET Async CTP) is not allowed from within a lock statement. From MSDN: An await expression cannot be used in a synchronous function, in a query expression, in the catch or finally block of an exception handling statement,…
Kevin
  • 8,312
  • 4
  • 27
  • 31
407
votes
22 answers

Avoid synchronized(this) in Java?

Whenever a question pops up on SO about Java synchronization, some people are very eager to point out that synchronized(this) should be avoided. Instead, they claim, a lock on a private reference is to be preferred. Some of the given reasons…
eljenso
  • 16,789
  • 6
  • 57
  • 63
375
votes
8 answers

When should one use a spinlock instead of mutex?

I think both are doing the same job,how do you decide which one to use for synchronization?
compile-fan
  • 16,885
  • 22
  • 59
  • 73
352
votes
7 answers

What is the difference between atomic / volatile / synchronized?

How do atomic / volatile / synchronized work internally? What is the difference between the following code blocks? Code 1 private int counter; public int getNextUniqueIndex() { return counter++; } Code 2 private AtomicInteger counter; public…
hardik
  • 9,141
  • 7
  • 32
  • 48
350
votes
5 answers

C# version of java's synchronized keyword?

Does c# have its own version of the java "synchronized" keyword? I.e. in java it can be specified either to a function, an object or a block of code, like so: public synchronized void doImportantStuff() { // dangerous code goes…
Soraz
  • 6,610
  • 4
  • 31
  • 48
304
votes
8 answers

How to Sync iPhone Core Data with web server, and then push to other devices?

I have been working on a method to sync core data stored in an iPhone application between multiple devices, such as an iPad or a Mac. There are not many (if any at all) sync frameworks for use with Core Data on iOS. However, I have been thinking…
Jason
  • 14,517
  • 25
  • 92
  • 153
243
votes
11 answers

Android Studio how to run gradle sync manually?

I'm debugging Gradle issues in Android Studio and see references to "Run gradle sync", but I'm not sure how to run this command. How do I run "Gradle sync" from Android studio or Mac terminal?
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
219
votes
7 answers

Mutex example / tutorial?

I was trying to understand how mutexes work. Did a lot of Googling but it still left some doubts of how it works because I created my own program in which locking didn't work. One absolutely non-intuitive syntax of the mutex is pthread_mutex_lock(…
Nav
  • 19,885
  • 27
  • 92
  • 135
217
votes
14 answers

node.js execute system command synchronously

I need in node.js function result = execSync('node -v'); that will synchronously execute the given command line and return all stdout'ed by that command text. ps. Sync is wrong. I know. Just for personal use. UPDATE Now we have mgutz's solution…
disfated
  • 10,633
  • 12
  • 39
  • 50
211
votes
11 answers

Synchronization vs Lock

java.util.concurrent API provides a class called as Lock, which would basically serialize the control in order to access the critical resource. It gives method such as park() and unpark(). We can do similar things if we can use synchronized…
daydreamer
  • 87,243
  • 191
  • 450
  • 722
207
votes
5 answers

How does @synchronized lock/unlock in Objective-C?

Does @synchronized not use "lock" and "unlock" to achieve mutual exclusion? How does it do lock/unlock then? The output of the following program is only "Hello World". @interface MyLock: NSLock @end @implementation MyLock - (id)init { …
David Lin
  • 5,538
  • 4
  • 25
  • 23
187
votes
8 answers

How do synchronized static methods work in Java and can I use it for loading Hibernate entities?

If I have a util class with static methods that will call Hibernate functions to accomplish basic data access. I am wondering if making the method synchronized is the right approach to ensure thread-safety. I want this to prevent access of info to…
tomato
  • 5,644
  • 13
  • 43
  • 48
187
votes
6 answers

Asynchronous Process inside a javascript for loop

I am running an event loop of the following form: var i; var j = 10; for (i = 0; i < j; i++) { asynchronousProcess(callbackFunction() { alert(i); }); } I am trying to display a series of alerts showing the numbers 0 through 10. The…
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
1
2 3
99 100