locking

What's the difference between isDeviceLocked and isKeyguardSecure in android's KeyguardManager?

三世轮回 提交于 2019-12-03 18:03:28
问题 Below is excerpted from http://developer.android.com/reference/android/app/KeyguardManager.html public boolean isDeviceLocked () Returns whether the device is currently locked and requires a PIN, pattern or password to unlock. Returns true if unlocking the device currently requires a PIN, pattern or password. public boolean isKeyguardSecure () Return whether the keyguard requires a password to unlock. Returns true if keyguard is secure. What's the difference between isDeviceLocked and

How to do proper Parallel.ForEach, locking and progress reporting

寵の児 提交于 2019-12-03 18:03:15
问题 I'm trying to implement the Parallel.ForEach pattern and track progress, but I'm missing something regarding locking. The following example counts to 1000 when the threadCount = 1 , but not when the threadCount > 1. What is the correct way to do this? class Program { static void Main() { var progress = new Progress(); var ids = Enumerable.Range(1, 10000); var threadCount = 2; Parallel.ForEach(ids, new ParallelOptions { MaxDegreeOfParallelism = threadCount }, id => { progress.CurrentCount++; }

C#: Invoke Event from Locked Block

萝らか妹 提交于 2019-12-03 17:27:58
I have usually heard that it is a good idea to unlock any locks before calling event listeners to avoid deadlock. However, since the lock {} block is reentrant by the same thread in C#, is it OK to call events from a locked block or do I need to make a copy of the relevant state data and invoke the event outside the lock block? If not, please give an example of when it would be a problem to call an event from within a lock {} block. Thanks I don't recall ever having a need to raise an event from within a lock statement. But it's not hard to imagine things going badly. When you raise an event,

Does making a Reentrant Lock static and make it a mutex?

南笙酒味 提交于 2019-12-03 16:59:12
问题 In Brian Goetz's book, Java Concurrency in Practice, his example of a Reentrant lock is programmed like this: Lock lock = new ReentrantLock(); However, I am curious to know if changing the above code to: private static final Lock lock = new ReentrantLock(); causes the lock to now act as a mutex, or if it is unnecessary and redundant. Thus, does the functionality of this code change if the lock is made private, static, and final? lock.lock(); try { //method stuff } finally { lock.unlock(); }

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

梦想与她 提交于 2019-12-03 16:58:53
问题 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>>

Lock analyser for Java application

倖福魔咒の 提交于 2019-12-03 16:49:48
I have two versions of a Java application which use different concurrency logic. I want to analyze and compare their performance (such amount of time a lock was acquired etc.) so that I can use the better one. I found out a tool IBM Lock Analyzer for Java but it is neither open source nor JDK version independent. It requires an IBM®-supplied Java™ SDK or JRE. Another tool also from IBM is Multicore Software Development Kit and has the following problem "The testing and analysis tool of MSDK runs on Sun JDK, except the lock analysis tool. The performance tool requires an IBM JDK." So can

Advantage of upgradable readlock?

a 夏天 提交于 2019-12-03 16:29:17
I was wondering what are the advantages of using a upgradable read lock as opposed performing these steps: Take read lock Check condition to see if we need to take write lock Release Read Lock Take Write Lock Perform update Release Write Lock One apparent disadvantage of the performing the above steps as opposed taking an upgradable read lock is, that there is an window of time between the steps 3 and 4, where another thread can take up a write lock. Apart from this advantage what other advantages do you find for taking upgradable read lock over the steps I have mentioned above? Let's consider

Use Java to lock a screen

浪子不回头ぞ 提交于 2019-12-03 16:18:36
Basically i just need to create an application (with sort of user access) which first screen is a fullscreen window that cannot be minimized or closed without entering valid username and password. Something like windows screensaver. Can it be done? What libraries should i look into? This is all i need, if my question is incomplete or unclear, feel free to ask! Once, I wrote something in Java, out of which you can't escape. Really impossible. It is for Windows. Here you go: import java.awt.Robot; import javax.swing.JFrame; public class WindowsSecurity implements Runnable { private JFrame frame;

How to call a python function from a foreign language thread (C++)

﹥>﹥吖頭↗ 提交于 2019-12-03 16:18:34
I am developing a program that use DirectShow to grab audio data from media files. DirectShow use thread to pass audio data to the callback function in my program, and I let that callback function call another function in Python. I use Boost.Python to wrapper my library, the callback function : class PythonCallback { private: object m_Function; public: PythonCallback(object obj) : m_Function(obj) {} void operator() (double time, const AudioData &data) { // Call the callback function in python m_Function(time, data); } }; Here comes the problem, a thread of DirectShow calls my PythonCallback,

How to correctly destroy pthread mutex

旧时模样 提交于 2019-12-03 16:16:16
How exactly i can destroy a pthread mutex variable ? Here is what i want to do. I want to have objects (structure variables) cached , which are looked up by key. I want to have minimum granularity of locks here. So i want to have a lock for each object probably embedded in the structure so that i can have object level locking. Now the problem is how to safely destroy these objects ? Looks like first step is to remove the object from the lookup table so that the object is not accessible in future that is fine. I want to free the object from the cache. Now how to destroy/free mutex correctly ?