ReentrantReadWriteLock: what’s the difference between ReadLock and WriteLock?

readLock.lock(); This means that if any other thread is writing (i.e. holds a write lock) then stop here until no other thread is writing. Once the lock is granted no other thread will be allowed to write (i.e. take a write lock) until the lock is released. writeLock.lock(); This means that if any other thread … Read more

Simple Deadlock Examples

Maybe a simple bank situation. class Account { double balance; void withdraw(double amount){ balance -= amount; } void deposit(double amount){ balance += amount; } void transfer(Account from, Account to, double amount){ sync(from); sync(to); from.withdraw(amount); to.deposit(amount); release(to); release(from); } } Obviously, should there be two threads which attempt to run transfer(a, b) and transfer(b, a) at … Read more

what is a loader lock?

For example, review this question: Loader lock error The general idea of loader lock: The system runs the code in DllMain inside a lock (as in – synchronization lock). Therefore, running non-trivial code inside DllMain is “asking for a deadlock” Answer I’ve mentioned is based on this article: Another reason not to do anything scary … Read more

How to use lockdep feature in linux kernel for deadlock detection

[*] To enable lockdep feature, edit .config file through menuconfig: make menuconfig And enable following in Hacking Options: 1. [*] Detect Hard and Soft Lockups 2. [*] Detect Hung Tasks 3. [*] RT Mutex debugging, deadlock detection 4. -*- Spinlock and rw-lock debugging: basic checks 5. -*- Mutex debugging: basic checks 6. -*- Lock debugging: … Read more

“Calling this from your main thread can lead to deadlock and/or ANRs while getting accesToken” from GoogleAuthUtil(Google Plus integration in Android)

Try it with an AsyncTask like this: AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void… params) { String token = null; try { token = GoogleAuthUtil.getToken( MainActivity.this, mGoogleApiClient.getAccountName(), “oauth2:” + SCOPES); } catch (IOException transientEx) { // Network or server error, try later Log.e(TAG, transientEx.toString()); } catch (UserRecoverableAuthException e) … Read more