locking

How to tell if user is on lock screen from service

假如想象 提交于 2019-12-03 06:58:28
I have simple service that running in the background and I just want to know when the user is on the lock screen or not, that way I know when to start a process. mopsled Check out a similar question asked here . Use KeyguardManager to check if the device is locked. KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); boolean showing = kgMgr.inKeyguardRestrictedInputMode(); 1) You need to firstly register a BroadcastReceiver in your Service to listen when power button is pressed (turns screen on/off): @Override public void onCreate() { super.onCreate();

Does the CLR perform “lock elision” optimization? If not why not?

梦想与她 提交于 2019-12-03 06:30:21
The JVM performs a neat trick called lock elision to avoid the cost of locking on objects that are only visible to one thread. There's a good description of the trick here: http://www.ibm.com/developerworks/java/library/j-jtp10185/ Does the .Net CLR do something similar? If not then why not? It's neat, but is it useful? I have a hard time coming up with an example where the compiler can prove that a lock is thread local. Almost all classes don't use locking by default, and when you choose one that locks, then in most cases it will be referenced from some kind of static variable foiling the

How can I release locks in Subversion recursively?

你。 提交于 2019-12-03 06:17:06
问题 I am having a problem with version control in Subversion. I checked out a working copy from respository and got locks on all of its files. Then, without releasing the locks I have deleted the folder from disk. I can't delete the folder from repository, since its got a lock If the I and try to release the locks recursively, it says there are no locks to be released. In Browse Repository view, I can only break the locks on particular, not folders recursively. How can I break the locks residing

skip-lock-tables and mysqldump

无人久伴 提交于 2019-12-03 06:09:11
Daily we run mysql dumps on about 50 individual databases, package them up and then store them offsite. Some of these databases are rather large and contain myisam tables (which CANNOT be changed so suggesting it is pointless).. I have been reading up on using the skip-lock-tables option when doing a dump but have not read what the downside would be. All I see are basically different iterations of "it could have adverse effects if data is inserted to a table while it is dumping." What are these adverse effects? Does it just mean we will miss those queries upon a restore or will it mean the

Is this (Lock-Free) Queue Implementation Thread-Safe?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 06:06:57
I am trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently. Would you please review it, and suggest any improvements/issues you find? Thank you. import java.util.concurrent.atomic.AtomicReference; public class LockFreeQueue<T> { private static class Node<E> { E value; volatile Node<E> next; Node(E value) { this.value = value; } } private AtomicReference<Node<T>> head, tail; public LockFreeQueue() { // have both head and tail point to a dummy node Node<T> dummyNode =

How are mutex and lock structures implemented?

倖福魔咒の 提交于 2019-12-03 05:51:21
问题 I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions for the CPUs MMU? 回答1: You may want to look at these links, but the main one is the Test-and-set on Wikipedia: http://en.wikipedia.org/wiki/Test-and-set How are mutexes implemented? You can also look at this patent: http://www.faqs.org/patents/app/20080222331 回答2: Most mutual exclusion and

Controlling duration of PostgreSQL lock waits

喜欢而已 提交于 2019-12-03 05:41:57
问题 I have a table called deposits When a deposit is made, the table is locked, so the query looks something like: SELECT * FROM deposits WHERE id=123 FOR UPDATE I assume FOR UPDATE is locking the table so that we can manipulate it without another thread stomping on the data. The problem occurs though, when other deposits are trying to get the lock for the table. What happens is, somewhere in between locking the table and calling psql_commit() something is failing and keeping the lock for a

should I lock 'event'?

你离开我真会死。 提交于 2019-12-03 05:41:27
should I lock event in the following case: event foo; thread A: will call foo += handler; thread B: will call foo -= handler; should I lock foo? Locking on foo is a bad idea, because the value will change each time. You should lock on a variable which doesn't change: private readonly object eventLock = new object(); private EventHandler fooHandler; public event EventHandler Foo { add { lock (eventLock) { fooHandler += value; } } remove { lock (eventLock) { fooHandler -= value; } } } private void OnFoo(EventArgs e) { EventHandler handler; lock (eventLock) { handler = fooHandler; } if (handler !

Should SELECT … FOR UPDATE always contain ORDER BY?

柔情痞子 提交于 2019-12-03 05:22:55
Let's say we execute... SELECT * FROM MY_TABLE FOR UPDATE ...and there is more than one row in MY_TABLE. Theoretically, if two concurrent transactions execute this statement, but it happens to traverse (and therefore lock) the rows in different order, a deadlock may occur. For example: Transaction 1: Locks row A. Transaction 2: Locks row B. Transaction 1: Attempts to lock row B and blocks. Transaction 2: Attempts to lock row A and deadlocks. The way to resolve this is to use ORDER BY to ensure rows are always locked in the same order. So, my question is: will this theoretical deadlock ever

Is spin lock useful in a single processor uni core architecture?

两盒软妹~` 提交于 2019-12-03 05:09:48
问题 I am confused by the function of spin lock. The spin lock is used to stop the process from re-scheduling. However, in a machine with just one core, is it useful to use spin lock to prevent context switching? 回答1: Short answer: no. According to http://uw714doc.sco.com/en/man/html.3synch/Intro.3synch.html Spin locks must not be used on a single processor system. In the best case, a spin lock on a single processor system will waste resources, slowing down the owner of the lock; in the worst case