synchronization

Silverlight HttpWebRequest syncronous call

£可爱£侵袭症+ 提交于 2019-12-22 09:17:54
问题 In my silverlight app I do a file upload. I break the file into chunks and then I upload each chunk. The problem is that I want to use the HttpWebRequest synchronously. My propblem is to ensure that all request are ok and to catch exceptions. Is that possible in Silverlight? I would like sopmething like: while(chunk) { try{ HttpWebRequest req = ... req.BeginGetRequestStream(new AsyncCallback(WriteCallback), req); //add data into request stream req.BeginGetResponseStream(new AsyncCallback

wait(), notify() and notifyAll() inside synchronized statement

旧城冷巷雨未停 提交于 2019-12-22 09:14:20
问题 I get following error when trying to do invoke notifyAll() inside a synchronized statement: Invoked Object.notify() outside synchronized context. Example: final List list = new ArrayList(); synchronized(list) {..... invoked notifyAll() here}; 回答1: You can only call wait() , notify() , and notifyAll() on the object that is being synchronized on: synchronized (list) { //... list.notifyAll(); } In other words, the calling thread must own the object's monitor. If, inside synchronized (list) , you

Extending HashMap<K,V> and synchronizing only puts

只愿长相守 提交于 2019-12-22 09:07:29
问题 I recently encountered a class on our code base that extends HashMap and synchronizes the put method. Aside from it being less efficient than using ConcurrentHashMap, what sort of problems may arise with extending HashMap and synchronizing only put(K,V)? Assume that we don't care whether get(K) returns the latest value or not(e.g. we are fine with threads overwriting each other and we don't care about the possible race conditions that may arise if the values of the map are used as locks

Strategies for keeping two mySQL databases (in separate locations) in sync? [duplicate]

余生长醉 提交于 2019-12-22 08:53:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Which is the best way to bi-directionally synchronize dynamic data in real time using mysql I need advice: How do I keep 2 mySQL databases (same structure) synced up across 2 locations? What am I doing: I am creating an application for a business with two locations. They need to share/update information in a database BUT the proprietor wants it to be internal not external, as he is worried about being able to

Native method synchronization

て烟熏妆下的殇ゞ 提交于 2019-12-22 08:27:31
问题 I have a native method method defined like this: public static native int doSomething(); However, this method is not thread-safe. So, I put a synchronized keyword on it, so it looks like this now: public static synchronized native int doSomething(); This appears to fix the problem, but I'm not sure if it actually does. Is this valid? Does it actually properly lock access to the method? 回答1: After reading the relevant JLS section, there is nothing in the JLS which prohibits static and native

C++ select() not waiting for timeout period

半腔热情 提交于 2019-12-22 08:26:03
问题 I'm trying to use the select function to accept input but every 2 seconds do something else if the user hasn't entered anything. The code below is waiting two seconds the first time select() is reached but once it prints the first "timed out" message it rapidly keep printing out "timed out" without waiting for 2 seconds, basically entering an infinite loop. Anyone know what the problem is? Thanks for any help. #include <stdio.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h>

Win32 reset event like synchronization class with boost C++

蹲街弑〆低调 提交于 2019-12-22 08:20:35
问题 I need some mechanism reminiscent of Win32 reset events that I can check via functions having the same semantics with WaitForSingleObject() and WaitForMultipleObjects() (Only need the ..SingleObject() version for the moment) . But I am targeting multiple platforms so all I have is boost::threads (AFAIK) . I came up with the following class and wanted to ask about the potential problems and whether it is up to the task or not. Thanks in advance. class reset_event { bool flag, auto_reset; boost

Behaviour of TMultiReadExclusiveWriteSynchronizer when promoting read-lock to write-lock

落爺英雄遲暮 提交于 2019-12-22 07:00:06
问题 How can I achieve a synchronization structure like that: Lock.BeginRead try if Changed then begin Lock.BeginWrite; try Update; finally Lock.EndWrite; end; // ... do some other stuff ... end; finally Lock.EndRead; end; without loosing the read lock after the EndWrite, so that no other writers can execute while this code block is executed. How does Delphi 2009's TMuliReadExclusiveWriteSynchronizer behave in this case? 回答1: It seems there are two criteria wrapped up in this question: "without

Unity3D — Send message to other mobile phones in the same vicinity

a 夏天 提交于 2019-12-22 06:53:11
问题 Say we have a group of 10 people, within 20m of one another. Each person has a mobile phone (iPhone / android / Windows phone). And one person taps the screen to send a message. And this is instantly registered by the others. Synchronisation is the key. It has to hit all target devices within a few milliseconds. How might I go about this? web sockets: I can't see this working as there is not guaranteed to be any Wi-Fi network. maybe I set up one phone as an access point, and the others

Unity3D — Send message to other mobile phones in the same vicinity

痞子三分冷 提交于 2019-12-22 06:52:22
问题 Say we have a group of 10 people, within 20m of one another. Each person has a mobile phone (iPhone / android / Windows phone). And one person taps the screen to send a message. And this is instantly registered by the others. Synchronisation is the key. It has to hit all target devices within a few milliseconds. How might I go about this? web sockets: I can't see this working as there is not guaranteed to be any Wi-Fi network. maybe I set up one phone as an access point, and the others