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
5
votes
4 answers

Assigning an object within a synchronized block based on that object (Java)

I ran into some (production!) code that looks like the snippet below: synchronized(some_object) { some_object = new some_object() } I would expect this to be subject to all sorts of horrible race conditions, and that a second thread Could…
Peter Friend
  • 750
  • 1
  • 7
  • 17
5
votes
2 answers

Why is the volatile field copied to a local variable when doing double check locking

I am reading about double check locking from Effective Java. The code does the following: private volatile FieldType field; FieldType getField() { FieldType result = field; if (result == null) { // First check (no locking) …
Jim
  • 18,826
  • 34
  • 135
  • 254
5
votes
3 answers

Serial code execution in a multi-threaded program in C++

The question: Is it possible to guarantee code execution can only occur in one thread at a time in a multi-threaded program? (Or something which approximates this) Specifically: I have a controller M (which is a thread) and threads A, B, C. I would…
5
votes
6 answers

How to use an Internet Subversion respository when developing code?

I've painted my self into a problem working with a Subversion project from CodePlex - for this I asked for help here. I have a local repository and CodePlex has it's Internet repository for the project, and the two don't mix :-(. But my dear…
Avi
  • 15,696
  • 9
  • 39
  • 54
5
votes
2 answers

Should class instance variables in Rails be set within a mutex?

Let's say I've got a Ruby class in my Rails project that is setting an instance variable. class Something def self.objects @objects ||= begin # some logic that builds an array, which is ultimately stored in @objects end end end Is…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
5
votes
1 answer

Catching 302 error and then redirecting in backbone.js sync method override

What I want to do is catch a 302 error which means a user is not logged in, and then redirecting that user to the login page of the website. Here's my backbone.js sync override right now: parentSynchMethod = Backbone.sync Backbone.sync = (method,…
5
votes
2 answers

CUDA __syncthreads() usage within a warp

If it was absolutely required for all the threads in a block to be at the same point in the code, do we require the __syncthreads function if the number of threads being launched is equal to the number of threads in a warp? Note: No extra threads or…
sj755
  • 3,944
  • 14
  • 59
  • 79
5
votes
2 answers

What are the differences between various threading synchronization options in Java?

Can someone explain the various differences between various synchronization methods in Java? Syncornized blocks (like monitors?) Locks - Java concurrent lock.lock()/lock.unlock() Semaphores..? Object.wait() & Object.notify() (like Mutex?) Other…
NightWolf
  • 7,694
  • 9
  • 74
  • 121
5
votes
1 answer

Overriding a synchronized method

What happens when a method in super class is synchronized, but you override the method in a subclass and don't synchronize it ?
user2434
  • 6,339
  • 18
  • 63
  • 87
5
votes
4 answers

How to make Multiple ajax requests in a loop return values sequentially?

I have to make a series of Ajax requests on a loop. Around 100 of them. And each request returns a JSONP variable. I extract data from the JSON and keep appending the value into a div. The problem is that I want the div to be appended with data in…
Pradep
  • 1,874
  • 5
  • 21
  • 31
4
votes
1 answer

Quartz Scheduler Cluster Time Sync

I've looked through Quartz documentation and I can't seem to find a definite answer to the question: What happens if I am using Quartz Scheduler in a clustered environment but the machines get out of synch (we would be using JobStoreTX)? Will Quartz…
4
votes
4 answers

Do i have to synchronize socket.send?

I have 2 classes where I have one to send commands to a socket, another which receives (and sometimes answers commands) . Do I have to synchronize this? Or is this not necessary? Both classes run in their own threads with the socket object passed…
Stackie Overflower
  • 201
  • 1
  • 6
  • 14
4
votes
3 answers

Is it possible to modify a non-volatile variable such that another thread is able to "see" the update?

I have a Thread-X which reads a non-volatile variable every second, doing so without any means of synchronization. Now I was wondering is there some way to modify that non-volatile variable on Thread-Y such that Thread-Y's write would be…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
4
votes
5 answers

HashMap synchronization for Map with value-incrementation

I have a questions regarding synchronization of HashMap. The background is that I am trying to implement a simple way of Brute-Force-Detection. I will use a map which has username as key and is used to save the amount of failed login attempts of the…
Mario B
  • 2,102
  • 2
  • 29
  • 41
4
votes
3 answers

Do accesses in a constructor to a shared static variable need to be synchronized?

I know that constructors cannot be synchronized in Java. Does this mean that if a constructor modifies a static variable within the class, and if constructors could be invoked from multiple threads, that the access needs to be synchronized, as…