synchronization

How do I take ownership of an abandoned boost::interprocess::interprocess_mutex?

可紊 提交于 2019-11-29 04:25:32
My scenario: one server and some clients (though not many). The server can only respond to one client at a time, so they must be queued up. I'm using a mutex ( boost::interprocess::interprocess_mutex ) to do this, wrapped in a boost::interprocess::scoped_lock . The thing is, if one client dies unexpectedly (i.e. no destructor runs) while holding the mutex, the other clients are in trouble, because they are waiting on that mutex. I've considered using timed wait, so if I client waits for, say, 20 seconds and doesn't get the mutex, it goes ahead and talks to the server anyway. Problems with this

When manipulating different array indices in C/C++ with two threads, is synchronization needed?

风流意气都作罢 提交于 2019-11-29 03:52:43
Suppose I have an array defined as follows: volatile char v[2]; And I have two threads (denoted by A, B respectively) manipulating array v . If I ensure that A, B use different indices at any time, that is to say, if A is now manipulating v[i] , then B is either doing nothing, or manipulating v[1-i] . I wonder is synchronization needed for this situation? I have referred to this question , however I think it is limited in Java. The reason why I ask this question is that I have been struggling with a strange and rare bug in a large project for days, and up to now, the only reason I could come

Wait() / notify() synchronization

走远了吗. 提交于 2019-11-29 03:00:02
问题 I'm trying to check how wait/notify works in java. Code: public class Tester { public static void main(String[] args) { MyRunnable r = new MyRunnable(); Thread t = new Thread(r); t.start(); synchronized (t) { try { System.out.println("wating for t to complete"); t.wait(); System.out.println("wait over"); } catch (InterruptedException e) { e.printStackTrace(); } } } } class MyRunnable implements Runnable { public void run() { System.out.println("entering run method"); synchronized (this) {

Emacs: Often switching between Emacs and my IDE's editor, how to automatically 'synch' the files?

北战南征 提交于 2019-11-29 02:56:32
问题 I very often need to do some Emacs magic on some files and I need to go back and forth between my IDE (IntelliJ IDEA) and Emacs. When a change is made under Emacs (and after I've saved the file) and I go back to IntelliJ the change appears immediately (if I recall correctly I configured IntelliJ to "always reload file when a modification is detected on disk" or something like that). I don't even need to reload: as soon as IntelliJ IDEA gains focus, it instantly reloads the file (and I hence

TSQL mutual exclusive access in a stored procedure

霸气de小男生 提交于 2019-11-29 02:41:19
Several web servers access a SQL Server to get a numeric code, when this code doesn't exist, it has to be autogenerated by the SQL Server. I need to ensure that even if two concurrent calls come in and the code doesn't exist, only one code is created and both calls return the same code. So I have to do something like this: begin lock if code exists return code else generate code return code end lock I've been reading a little about isolation levels and table locking, but I have a terrible mess with all that. First I thought that a SERIALIZABLE isolation level is what I need, but apparently it

Do I need to Dispose() or Close() an EventWaitHandle?

旧时模样 提交于 2019-11-29 02:39:11
问题 If I am using EventWaitHandle (or AutoResetEvent , ManualResetEvent ) to synchronise between threads then do I need to call the Close() or Dispose() methods on that event handle when I am done with it? EventWaitHandle inherits from WaitHandle , which implements IDisposable . And FxCop complains if I don't implement IDisposable on any class that contains an EventWaitHandle . So this suggests that I do need to call it. However none of these MSDN usage examples call Dispose() or Close() : http:/

Add account automatically

…衆ロ難τιáo~ 提交于 2019-11-29 02:39:05
My application needs to synchronize some data from server. I added necessary classes (similarly to SampleSyncAdapter) now I can add account via "Settings/Sync and Accounts". But I want to have already added my account and working synchronization just after application is installed (I do not want user to do any manual changes in settings). How to do this? There is Android AtLeap library which contains helper classes to use Account Authenticator. Have a look at it https://github.com/blandware/android-atleap A bit late but... Account account = new Account("Title", "com.package.nom"); String

How to synchronize databases in different servers in SQL Server 2008?

纵饮孤独 提交于 2019-11-29 02:35:46
问题 I have 2 databases that have the same structure, one on a local machine and one on the company's server. Every determined amount of time, the data from the local DB should be synchronized to the server DB. I have a general idea on how to do this - create a script that somehow "merges" the information that is not on the server DB, then make this script run as a scheduled job for the server. However, my problem lies in the fact that I am not very well experienced with this. Does SQL Server

How do I synchronize (lock/unlock) access to a file in bash from multiple scripts?

China☆狼群 提交于 2019-11-29 02:12:59
问题 I'm writing scripts that will run in parallel and will get their input data from the same file. These scripts will open the input file, read the first line, store it for further treatment and finally erase this read line from the input file. Now the problem is that multiple scripts accessing the file can lead to the situation where two scripts access the input file simultaneously and read the same line, which produces the unacceptable result of the line being processed twice. Now one solution

Nested synchronized keyword

半腔热情 提交于 2019-11-29 02:08:28
问题 I have this code in Java: public void doSomeThing() { synchronized (this) { doSomeThingElse(); } } public void doSomeThingElse() { synchronized (this) { // do something else } } Can this code block? I mean, Can this code wait for ever? 回答1: As the java documentation describes for Reentrant locking : a thread can acquire a lock that it already owns The second synchronized block is using the same lock and thus will always be useable as the lock has already been aquired in the outer method. No,