synchronization

Clojure STM ( dosync ) x Java synchronize block

人盡茶涼 提交于 2019-12-03 11:43:34
What is the difference between Clojure STM (dosync) approach and Java synchronize Block? I'm reading the code below from "The sleeping barber" problem. ( http://www.bestinclass.dk/index.clj/2009/09/scala-vs-clojure-round-2-concurrency.html ) (defn the-shop [a] (print "[k] entering shop" a) (dosync (if (< (count @queue) seats) (alter queue conj a) (print "[s] turning away customer" a)))) To avoid race conditions, dosync is used, so i ask myself "What is the difference (STM) from Java synchronize block" ? Will it block this critical code ? Thanks in advance ! Dantas dosync and synchronized give

What to use instead of the “lock” statement when the code is running on multiple machines?

冷暖自知 提交于 2019-12-03 11:20:42
The lock statement ensures that one thread does not enter a critical section of code while another thread is in the critical section. However, it won't work if the workload is spread across a farm of servers (e.g. a few IIS servers + a load balancer). Does .NET support such a scenario? Is there any class that can be used to control the execution of a critical code section by threads running on multiple machines? If not, is there any standard method of handling such problems? This question was inspired by a discussion that started here but is not limited to SharePoint or ASP.NET. Kit If you

what if notify() is called before wait()?

血红的双手。 提交于 2019-12-03 11:12:39
I have a situation where a notify() 'can' be called before a wait(). I am trying to make a simulator to schedule its next event when I 'notify' him by sending him messages. So I have devised a wait->notify->scedule chain void Broker::pause() { boost::unique_lock<boost::mutex> lock(m_pause_mutex); { std::cout << "pausing the simulation" << std::endl; m_cond_cnn.wait(lock); std::cout << "Simulation UNpaused" << std::endl; // the following line causes the current function to be called at // a later time, and a notify() can happen before the current function // is called again Simulator::Schedule

How to correctly use sync.Cond?

你。 提交于 2019-12-03 11:00:52
问题 I'm having trouble figuring out how to correctly use sync.Cond. From what I can tell, a race condition exists between locking the Locker and invoking the condition's Wait method. This example adds an artificial delay between the two lines in the main goroutine to simulate the race condition: package main import ( "sync" "time" ) func main() { m := sync.Mutex{} c := sync.NewCond(&m) go func() { time.Sleep(1 * time.Second) c.Broadcast() }() m.Lock() time.Sleep(2 * time.Second) c.Wait() } [Run

Don't understand the need for Monitor.Pulse()

守給你的承諾、 提交于 2019-12-03 10:55:04
问题 According to MSDN, Monitor.Wait() : Releases the lock on an object and blocks the current thread until it reacquires the lock. However, everything I have read about Wait() and Pulse() seems to indicate that simply releasing the lock on another thread is not enough. I need to call Pulse() first to wake up the waiting thread. My question is why? Threads waiting for the lock on a Monitor.Enter() just get it when it's released. There is no need to "wake them up". It seems to defeat the usefulness

Synchronizing Client-Server game state

为君一笑 提交于 2019-12-03 10:35:16
问题 I am making a client server MMO style game. So far I have the framework set up so that the server and clients interact with each other in order to provide state updates. The server maintains the game state and periodically calculates the next state and then it every once in a while (every n milliseconds) it sends out the new state to all the clients. This new state is able to be viewed and reacted to on the client side by the user. These actions are then sent back to the server to be

In Lucene, how can I find out if the IndexSearcher or IndexWriter is being used in another thread or not?

霸气de小男生 提交于 2019-12-03 10:03:52
Lucene documentation states that single instances of IndexSearcher and IndexWriter should be used for each index in the whole application, and across all threads. Also, writes to an index will not be visible until the index is re-opened. So, I'm trying to follow these guides, in a multi-threaded setup. (a few threads writing, multiple user threads searching). I don't want to re-open the index on every change, rather, I want to keep searcher instance not older than a certain amount of time (say, like 20 seconds). A central component is responsible to open index readers and writers, and keep the

Core Data syncing

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 10:03:50
问题 is there a way to automatically sync my Core Data Model with a server (preferably REST)? Thanks 回答1: Apple has shared their Sync Services Framework it is documented here: http://developer.apple.com/documentation/Cocoa/Conceptual/SyncServices/SyncServices.html This section is specifically related to syncing managed objects: http://developer.apple.com/documentation/Cocoa/Conceptual/SyncServices/Articles/UsingCoreData.html#//apple_ref/doc/uid/TP40005232 As for which style of data transfer is

Implementation of set reconciliation algorithm

丶灬走出姿态 提交于 2019-12-03 10:01:22
问题 I'm looking for implementations of set reconciliation algorithm. The problem is following: there are two sets with elements identified by some relatively compact value (e.g. UUID or MD5/SHA1/whatever hash) sitting on different machines. These sets differ in relatively few elements and I want to synchronize these sets while transferring minimal amount of data. Most of googling leads here. This is GPL'd implementation of what seems to be the state-of-art approach to the task. The problem is

Bounded-waiting Mutual Exclusion with test and set

為{幸葍}努か 提交于 2019-12-03 09:57:31
问题 I am reading the famous Operating System Concepts book of (Avi Silberschatz, Peter Baer Galvin, Greg Gagne) edition 9: http://codex.cs.yale.edu/avi/os-book/OS9/ In the process synchronization chapter, there is an algorithm for "Bounded-waiting Mutual Exclusion with test_and_set" as follow: do { waiting[i] = true; key = true; // <-- Boolean variable that I do not see its utility while (waiting[i] && key) // <-- the value of the key variable here is always true key = test_and_set(&lock); // <--