locking

Know when to show a passcode lock

家住魔仙堡 提交于 2019-11-30 05:22:21
I am developing an application that needs to display a passcode screen whenever a user leaves the app and comes back (be it through a screen lock, or going back to the home screen through the back or home button). I had it working using the following: The starting activity would call for the passcode check on startup, and each activity added the following functionality to their onPause method: @Override public void onPause() { super.onPause(); if (!isFinishing()) { new PasscodeCheckTask(this.getApplicationContext(),this).execute(); } } The PassocdeCheckTask looks like the following. It checks

Doing locking in ASP.NET correctly

天大地大妈咪最大 提交于 2019-11-30 05:20:31
I have an ASP.NET site with a fairly slow search function, and I want to improve performance by adding the results to the cache for one hour using the query as the cache-key: using System; using System.Web; using System.Web.Caching; public class Search { private static object _cacheLock = new object(); public static string DoSearch(string query) { string results = ""; if (HttpContext.Current.Cache[query] == null) { lock (_cacheLock) { if (HttpContext.Current.Cache[query] == null) { results = GetResultsFromSlowDb(query); HttpContext.Current.Cache.Add(query, results, null, DateTime.Now.AddHours

Lock table while inserting

可紊 提交于 2019-11-30 05:17:27
I have a large table that get populated from a view. This is done because the view takes a long time to run and it is easier to have the data readily available in a table. A procedure is run every so often that updates the table. TRUNCATE TABLE LargeTable INSERT INTO LargeTable SELECT * FROM viewLargeView WITH (HOLDLOCK) I would like to lock this table when inserting so if someone tries to select a record they will not receive none after the truncate. The lock I am using seems to lock the view and not the table. Is there a better way to approach this problem? Darren BEGIN TRY BEGIN TRANSACTION

Python threading and GIL

被刻印的时光 ゝ 提交于 2019-11-30 05:17:18
问题 I was reading about the GIL and it never really specified if this includes the main thread or not (i assume so). Reason I ask is because I have a program with threads setup that modify a dictionary. The main thread adds/deletes based on player input while a thread loops the data updating and changing data. However in some cases a thread may iterate over the dictionary keys where one could delete them. If there is a so called GIL and they are run sequentially, why am I getting dict changed

Lock Android Device to Run Only One App

别等时光非礼了梦想. 提交于 2019-11-30 05:11:39
I was wondering if anyone had a relatively simple solution for us. We created an app to be used by our clients on android devices that we give them. We would like the client to only be able to use our app and have limited access to everything else (i.e. settings, email etc.) What is the best way to achieve this without using 3rd party apps. Thank you in advance! This may not help but the L preview has a task locking feature included that may be of some insight, I'm not aware of how it functions as yet Task locking The L Developer Preview introduces a new task locking API that lets you

Linux Kernel Preemption during spin_lock and mutex_lock

两盒软妹~` 提交于 2019-11-30 05:11:14
When a process in the kernel space is holding a spin_lock , the process cannot be preempted due to any of the following conditions : When the time-slice of the process gets exhausted When a high priority process becomes runnable When an interrupt occurs However the process can yield the processor if it blocks, sleeps, or explicitly call schedule() . Is my understanding correct? When a process in the kernel space is holding a mutex_lock , can the process be preempted due to the above conditions listed as 1, 2 and 3. Current implementations of spin locks use two entirely separate mechanisms to

C# Threading issue with AutoResetEvent

前提是你 提交于 2019-11-30 05:11:03
问题 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

Do static locks work across different children classes?

风格不统一 提交于 2019-11-30 05:02:57
问题 If I have abstract class Parent { static object staticLock = new object(); public void Method1() { lock(staticLock) { Method2(); } } protected abstract Method2(); } class Child1 : Parent { protected override Method2() { // Do something ... } } class Child2 : Parent { protected override Method2() { // Do something else ... } } Will calls to new Child1().Method1() and new Child2().Method1() use the same lock? 回答1: Yes. A derived class does not get a new copy of the static data from the base

Creating a lock that preserves the order of locking attempts in C++11

空扰寡人 提交于 2019-11-30 05:01:51
Is there a way to ensure that blocked threads get woken up in the same order as they got blocked? I read somewhere that this would be called a "strong lock" but I found no resources on that. On Mac OS X one can design a FIFO queue that stores all the thread ids of the blocked threads and then use the nifty function pthread_cond_signal_thread_np() to wake up one specific thread - which is obviously non-standard and non-portable. One way I can think of is to use a similar queue and at the unlock() point send a broadcast() to all threads and have them check which one is the next in line. But this

Can I tell if the iPhone has a passcode?

ε祈祈猫儿з 提交于 2019-11-30 04:56:49
问题 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