locking

Can I tell if the iPhone has a passcode?

余生颓废 提交于 2019-11-30 21:11:40
I'm developing an application that asks for a PIN when you start it. That's not great, but I can live with it. The problem is I'm being asked to ask for the PIN each time the phone wakes from sleep, too. Combined with the OS asking for its passcode, it's too much. Is there any legitimate way to detect if the phone has a passcode required for waking, so I can skip requiring a PIN in this case? I don't want to know the PIN and I don't actually care if it was locked (for instance, if the phone was asleep very briefly), I just want to know that the data is in some way "protected." For AppStore or

C# Threading issue with AutoResetEvent

拈花ヽ惹草 提交于 2019-11-30 21:07:57
How to properly synchronize this? At the moment it is possible that SetData is called after e.WaitOne() has completed so d could be already set to another value. I tried to insert locks but it resulted into a deadlock. AutoResetEvent e = new AutoResetEvent(false); public SetData(MyData d) { this.d=d; e.Set(); // notify that new data is available } // This runs in separate thread and waits for d to be set to a new value void Runner() { while (true) { e.WaitOne(); // waits for new data to process DoLongOperationWith_d(d); } } Will the best solution be to introduce a new boolean variable

What's wrong with this fix for double checked locking?

岁酱吖の 提交于 2019-11-30 20:57:50
So I've seen a lot of articles now claiming that on C++ double checked locking, commonly used to prevent multiple threads from trying to initialize a lazily created singleton, is broken. Normal double checked locking code reads like this: class singleton { private: singleton(); // private constructor so users must call instance() static boost::mutex _init_mutex; public: static singleton & instance() { static singleton* instance; if(!instance) { boost::mutex::scoped_lock lock(_init_mutex); if(!instance) instance = new singleton; } return *instance; } }; The problem apparently is the line

Are empty synchronized blocks optimized out by Java compiler?

非 Y 不嫁゛ 提交于 2019-11-30 20:43:08
Suppose somewhere in my code I write an empty synchronized block: synchronized(obj){ //No code here } So as the synchronized block does not contain any code, will JIT compiler optimize that out by not locking on obj as it will be of no use? Java compiler does similar tricks such as Lock coarsening but will this synchronized block be also optimized out? EDIT: As per the point made by assylias, synchronized(new Object()){ //empty block } will the JIT compiler now be able to optimize this out, since I am using an Object which doesn't escape my method? This can't be optimized away on the basis of

How to prevent two CUDA programs from interfering

て烟熏妆下的殇ゞ 提交于 2019-11-30 20:34:26
I've noticed that if two users try to run CUDA programs at the same time, it tends to lock up either the card or the driver (or both?). We need to either reset the card or reboot the machine to restore normal behavior. Is there a way to get a lock on the GPU so other programs can't interfere while it's running? Edit OS is Ubuntu 11.10 running on a server. While there is no X Windows running, the card is used to display the text system console. There are multiple users. If you are running on either Linux or Windows with the TCC driver, you can put the GPU into compute exclusive mode using the

Better solution to multithreading riddle?

元气小坏坏 提交于 2019-11-30 20:12:55
Here's the task: I need to lock based on a filename. There can be up to a million different filenames. (This is used for large-scale disk-based caching). I want low memory usage and low lookup times, which means I need a GC'd lock dictionary. (Only in-use locks can be present in the dict). The callback action can take minutes to complete, so a global lock is unacceptable. High throughput is critical. I've posted my current solution below, but I'm unhappy with the complexity. EDIT: Please do not post solutions that are not 100% correct. For example, a solution which permits a lock to be removed

Locking with timeout pattern

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:09:14
lock uses this pattern if(Monitor.Enter(lock)) try { ... } finally { Monitor.Exit(lock); } // using this style to reduce post "height" if we don't want to wait infinite we can provide timeout if(!Monitor.TryEnter(lock, timeout)) throw new TimeoutException(); try { ... } finally { Monitor.Exit(lock); } I have scenario when method has to obtain multiple locks before it start doing anything. This looks awful: if(!Monitor.TryEnter(lockA, timeout)) throw new TimeoutException(); try { if(!Monitor.TryEnter(lockB, timeout)) throw new TimeoutException(); try { if(!Monitor.TryEnter(lockC, timeout))

select_for_update in development Django

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:08:52
The Django documentation states that: If you were relying on “automatic transactions” to provide locking between select_for_update() and a subsequent write operation — an extremely fragile design, but nonetheless possible — you must wrap the relevant code in atomic(). Is the reason why this no longer works is that autocommit is done at the database layer and not the application layer? Previously the transaction would be held open until a data-altering function is called : Django’s default behavior is to run with an open transaction which it commits automatically when any built-in, data

PostgreSQL and locking

我们两清 提交于 2019-11-30 20:06:14
问题 Hopefully some smarter DBAs than I can help me find a good solution for what I need to do. For the sake of discussion, lets assume I have a table called 'work' with some number of columns, one of which is a column that represents ownership of that row of work from a given client. The scenario is that I'll have 2 clients connected and polling a table for work to be done, when a row (or some number of rows) shows up, the first client that selects the rows will also update them to imply

Lock an Android Phone [duplicate]

时间秒杀一切 提交于 2019-11-30 19:39:34
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Lock the android device programatically I want to be able to lock the Android phone with a password when I run a method. Does anyone have a reference or sample code for me to refer. Thanks EDIT I have tried using KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); lock.reenableKeyguard(); as said by the answer below, but I