synchronization

Can Monitor.Enter throw an exception?

China☆狼群 提交于 2019-12-22 06:51:11
问题 Can Monitor.Enter throw any exception. I am doing a code review and find that Monitor.Enter is before try block. Do you see any issues with in? Monitor.Enter(...) try { ... } finally { Monitor.Exit(..) } 回答1: This is the correct pattern, whether Enter() throws (can throw) or not. Only after the call to Enter() succeeds your code is under the responsibility to call Exit() . Suppose the call to Enter() fails. Then calling the corresponding Exit() is simply incorrect, it will make matters worse.

git server replication

主宰稳场 提交于 2019-12-22 06:24:37
问题 We are using git for a multi site project and both the repo and the team have grown substantially. Therefore remote sites are suffering. I would like to add new git servers to the remote sites to decrease the load on our git server and to make the downloads faster. However I am not sure how to keep these synchronized. Is there any way to replicate git servers atomically? And if not any other suggestions? 回答1: You could have a main "write" repo, and multiple remote, read only , repos pull from

Android Sync Adapter Resources [closed]

孤人 提交于 2019-12-22 05:25:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Does anyone know of any books or online resources (except the dev docs) that cover the Sync Adapter and its usage? Struggling to find any good material myself. Or.. does anyone know of any alternative libraries for conducting remote sync services? Thanks 回答1: There really isn't any good resources at this point.

In Java, do methods that don't use static or class variables need to be synchronized?

主宰稳场 提交于 2019-12-22 04:47:10
问题 Do methods that only use local variables inside suffer any threading issues ?. Somewhere it was mentioned that the method with local variables are copied to each thread stack frame to work with and do not need to synchronized for multithreaded implementation unless it uses class level or static references/variables ? 回答1: If your method only operates on parameters and locally-defined (as opposed to class member) variables then there are zero synchronization problems to worry about. But...

C++0x atomic template implementation

人盡茶涼 提交于 2019-12-22 04:08:27
问题 I know that similar template exits in Intel's TBB, besides that I can't find any implementation on google or in Boost library. 回答1: You can find discussions about this feature implementation in boost there : http://lists.boost.org/Archives/boost/2008/11/144803.php > Can the N2427 - C++ Atomic Types and Operations be implemented > without the help of the compiler? No. They don't need to be intrinsics if you can write inline assembler (or separately-compiled assembler for that matter) then you

Semaphore Vs Mutex

五迷三道 提交于 2019-12-22 00:20:11
问题 I was reading a bit of Mutex and semaphore. I have piece of code int func() { i++; return i; } i is declared somewhere outside as a global variable. If i create counting semaphore with count as 3 won't it have a race condition? does that mean i should be using a binary semaphore or a Mutex in this case ? Can somebody give me some practical senarios where Mutex, critical section and semaphores can be used. probably i read lot. At the end i am a bit confused now. Can somebody clear the thought.

Realistic deadlock example in CUDA/OpenCL

拈花ヽ惹草 提交于 2019-12-21 22:31:26
问题 For a tutorial I'm writing, I'm looking for a "realistic" and simple example of a deadlock caused by ignorance of SIMT / SIMD. I came up with this snippet, which seems to be a good example. Any input would be appreciated. … int x = threadID / 2; if (threadID > x) { value[threadID] = 42; barrier(); } else { value2[threadID/2] = 13 barrier(); } result = value[threadID/2] + value2[threadID/2]; I know, it is neither proper CUDA C nor OpenCL C. 回答1: A simple deadlock that is actually easy to catch

Synchronization on arguments of static methods

不打扰是莪最后的温柔 提交于 2019-12-21 21:51:20
问题 I have a question concerning the java synchronization with static methods. More precisely, I have a class with static methods that can be used concurrently by several threads. The principal static method of my class has one argument and calls the other auxiliary static methods one after the other passing them this argument. My question is the following: since the class can be used by multiple threads at a time, isn't there a risk that another thread replaces the argument by another one? I had

How to synchronize the publishers and subscribers in extended PUB-SUB pattern with Intermediary in ZeroMQ in c++?

混江龙づ霸主 提交于 2019-12-21 21:20:37
问题 Extended PUB/SUB topology I have multiple publishers and multiple subscribers in a use case with 1 intermediary. In the ZeroMQ guide, I learnt about synchronizing 1 publisher and 1 subscriber, using additional REQ/REP sockets. I tried to write a synchronization code for my use case, but it is getting messy if I try to write code according to logic given for 1-1 PUB/SUB . The publisher code when we have only 1 publisher is : //Socket to receive sync request zmq::socket_t syncservice (context,

How to protect init function of a C based library?

家住魔仙堡 提交于 2019-12-21 21:18:10
问题 I have written a C based library and for it to work in multi-thread parallely, I create some global mutexes in the init function. I expect the init function to be called in the main thread before the library APIs are used in multi-thread. But, if the init function itself is called in multi-thread directly, then it is a problem. Is there a way to protect the init function itself from my library? One way I can think of is to ask the application to create a mutex and protect parallel calls to my