locking

How to use/create unique_lock in c++?

China☆狼群 提交于 2019-12-21 03:09:23
问题 Please, can anybody explain how to use and create an unique_lock in c++? It should be used both to get mutual exclusion to any procedure of the monitor and to be able to perform wait() on the condition variable...I'm not understanding from the documentation how I am supposed to create it. Is necessary a mutex? Here is a pseudo-code: /* compile with g++, flags -std=c++0x -lpthread */ #include <condition_variable> #include <mutex> #include <thread> #include <iostream> #include <string.h>

Can we lock the app while app goes to sleep mode in IPhone?

痞子三分冷 提交于 2019-12-21 03:02:32
问题 I am working an app where lock option is included.My app starts with passcode screen.If I enter correct code then it navigates to next screen.If I dont use the app for long time it goes to sleep mode.When the user wants to run the app now, the passcode screen should appear and the user has to enter the code again.Is it possible?Is there any tutorial for this?Please dont mind to post the related code if you have done it.Thanks in advance. 回答1: Yes ofcourse it is possible. You must open the

Android - Prevent user from closing app

会有一股神秘感。 提交于 2019-12-20 20:47:09
问题 I've an android application that will be used in a restaurant, so I want that users can't exit from the app. The only thing that users can, is using application. (If possible only admin can exit from app, by logging in or restarting device, I don't know which is the best way). Is there a solution or other way to do this? Thank you very much! 回答1: What you are looking for is a Kiosk mode app, I remember reading that on 4.2 it is possible to write home screen application that in behaviour will

How to tell if user is on lock screen from service

爱⌒轻易说出口 提交于 2019-12-20 20:38:11
问题 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. 回答1: 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(); 回答2: 1) You need to firstly register a BroadcastReceiver in your Service to listen when

should I lock 'event'?

烈酒焚心 提交于 2019-12-20 18:08:14
问题 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? 回答1: 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; } } }

Mixing synchronized() with ReentrantLock.lock()

十年热恋 提交于 2019-12-20 11:59:05
问题 In Java, do ReentrantLock.lock() and ReetrantLock.unlock() use the same locking mechanism as synchronized() ? My guess is "No," but I'm hoping to be wrong. Example: Imagine that Thread 1 and Thread 2 both have access to: ReentrantLock lock = new ReentrantLock(); Thread 1 runs: synchronized (lock) { // blah } Thread 2 runs: lock.lock(); try { // blah } finally { lock.unlock(); } Assume Thread 1 reaches its part first, then Thread 2 before Thread 1 is finished: will Thread 2 wait for Thread 1

How To Find The Table Names Which Are Locked (Specific to any transaction)

白昼怎懂夜的黑 提交于 2019-12-20 09:45:08
问题 Is there any way to list out the locked tables and to kill the transactions if we want them to be unlocked immediately. Or is there any other terminology do we need to follow for above operation i am seeking for. Any Help or guidance will be appreciated. 回答1: This will show all databases with exclusive locks being held (which may include transient ones held at the time this is run), using the sys.dm_tran_locks DMV: select d.*, l.* from sys.dm_tran_locks l join sys.databases d on l.resource

Prevent two threads entering a code block with the same value

不问归期 提交于 2019-12-20 09:40:00
问题 Say I have this function (assume I'm accessing Cache in a threadsafe way): object GetCachedValue(string id) { if (!Cache.ContainsKey(id)) { //long running operation to fetch the value for id object value = GetTheValueForId(id); Cache.Add(id, value); } return Cache[id]; } I want to prevent two threads from running the " long running operation " at the same time for the same value . Obviously I can wrap the whole thing in a lock(), but then the whole function would block regardless of value and

Does the C# Yield free a lock?

拟墨画扇 提交于 2019-12-20 09:29:37
问题 I have the following method: public static IEnumerable<Dictionary<string, object>> GetRowsIter (this SqlCeResultSet resultSet) { // Make sure we don't multi thread the database. lock (Database) { if (resultSet.HasRows) { resultSet.Read(); do { var resultList = new Dictionary<string, object>(); for (int i = 0; i < resultSet.FieldCount; i++) { var value = resultSet.GetValue(i); resultList.Add(resultSet.GetName(i), value == DBNull.Value ? null : value); } yield return resultList; } while

ZooKeeper alternatives? (cluster coordination service) [closed]

情到浓时终转凉″ 提交于 2019-12-20 07:58:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . ZooKeeper is a highly available coordination service for data centers. It originated in the Hadoop project. One can implement locking, fail over, leader election, group membership and other coordination issues on top of it. Are there any alternatives to ZooKeeper? (free software of course) 回答1: I've looked