unlock

Java多线程锁的知识实例讲解

时光毁灭记忆、已成空白 提交于 2019-12-01 10:10:44
Lock Lock提供了与synchronized类似的同步功能,只是在显式的获取和释放锁,因此有了锁获取和释放的可操作性、可中断的获取锁以及超时获取锁等多种同步特性。 代码实例: Lock lock = new ReentrantLock(); lock.lock(); try{ }finally{ lock.unlock(); } 特性 尝试非阻塞地获取锁:当前线程尝试获取锁,如果这一时刻锁没有被其它线程获取到,则成功获取并持有锁; 能被中断地获取锁:获取到的锁的线程能够响应中断,当获取到锁的线程被中断时,中断异常将会抛出,同时锁被释放; 超时获取锁:在指定时间后获取锁,如果时间到了无法获取,则返回 队列同步器 队列同步器是用来构建锁或其它同步 组件 的基础框架 它使用一个 int变量表示同步状态,通过内置的FIFO队列来完成资源获取线程的排队工作 重写同步器指定方法是,需要使用以下 3个方法访问或修改同步状态 getState():获取当前同步状态 setState(int newState):设置当前同步状态 compareAndSetState(int expect, int update):使用CAS设置当前状态,保证状态设置原子性 重入锁 ReentrantLock:支持重进入的锁,可以支持一个线程对资源的重复加锁,同时还支持获取锁时的公平和非公平性选择。

Android check if lockscreen is set

不问归期 提交于 2019-12-01 05:19:49
i need to check if the lockscreen does have a Pin or something more secure (Password, Fingerprint etc.). Im able to check if there is a Pin, Password or a Pattern. KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return keyguardManager.isKeyguardSecure(); My Problem is that i cant detect if the lockscreen is a Pattern or something lower. I tried this: int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED); but its deprecated and throws me an error. I also tried this: long mode2 = Settings.Secure.getLong

Unlock Android phone programmatically?

纵然是瞬间 提交于 2019-12-01 05:18:23
I want to write the code on how to unlock the Android Phone programmatically. I want lock or unlock the phone when the user taps the proximity sensor. public class MyActivity extends Activity{ private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF"; BroadcastReceiver myReceiver; Context context; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); context = this; final IntentFilter theFilter = new IntentFilter(); theFilter.addAction(ACTION); context.registerReceiver(myReceiver, theFilter);

Unlock Android phone programmatically?

折月煮酒 提交于 2019-12-01 02:25:21
问题 I want to write the code on how to unlock the Android Phone programmatically. I want lock or unlock the phone when the user taps the proximity sensor. public class MyActivity extends Activity{ private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF"; BroadcastReceiver myReceiver; Context context; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); context = this; final IntentFilter

C++并发-互斥元

穿精又带淫゛_ 提交于 2019-11-30 07:14:59
1.std::mutex类 1.构造函数,std::mutex不允许拷贝构造,也不允许 move 拷贝,最初产生的 mutex 对象是处于 unlocked 状态的。 2.lock(),调用线程将锁住该互斥量。线程调用该函数会发生下面 3 种情况:①如果该互斥量当前没有被锁住,则调用线程将该互斥量锁住,直到调用 unlock之前,该线程一直拥有该锁。②如果当前互斥量被其他线程锁住,则当前的调用线程被阻塞住。③如果当前互斥量被当前调用线程锁住,则会产生死锁(deadlock)。 3.unlock(), 解锁,释放对互斥量的所有权 4.unlock 和lock配套使用 5.必须在每个离开函数的路径上调用unlock。 2.std::lock_guard类 std::lock_guard使用起来比较简单,除了构造函数外没有其他成员函数。 优势在于不用配对使用 #include <thread> #include <iostream> #include <mutex> std::mutex some_mutex; void add() { std::lock_guard<std::mutex> guard(some_mutex); } 3.使用std::unique_lock灵活锁定 为了实现锁粒度,std::lock_guard就显得不够灵活,一个例子: #include <thread

How to detect if PIN/password/pattern is required to unlock phone?

谁都会走 提交于 2019-11-30 03:24:39
How can I detect if the phone is locked by a password, pin or pattern? thank you! Two methods Check programatically - API 16+ https://gist.github.com/doridori/54c32c66ef4f4e34300f Note that you dont need to check for face unlock as that requires that a pin/pass fallback is set. Device Admin Policies Can also look into the Device Admin Policies which allow restrictions on how the app is setup regarding security including pin/pass set restrictions Device Administration Enhancing Security with Device Management Policies As an aside, these are the lock types you want to check for if using an

Unlock the Screen Programmatically

落花浮王杯 提交于 2019-11-29 06:39:52
I have a share button in the GCM notification . On click of the share button, I need to launch share intent. Everything works perfectly. Only problem that I'm facing is Lollipop lock screen feature. When I click share button from lock screen, my intent dialog appears below the lock screen and user has to unlock the screen to see the dialog. I want to unlock the screen programatically, when share button is clicked. I tried with Power Manager, But all it's wakeClock flags are deprecated and WindowManager.LayoutParams.Flag_KEEP_SCREEN_ON is recommened to use. But I'm not using activity here. I'm

Activity handle when screen unlocked

浪子不回头ぞ 提交于 2019-11-29 04:37:13
So I have my onResume command restarting a stopped thread which runs my game loop. This works perfectly for resuming the app when closed by home button or by focusing on another app. However, when you turn the screen off then on again, the activities onResume command fires right away before screen is unlocked. I need my activity to know when the screen is unlocked so it can restart the thread at the appropriate time. Has anyone had this happen before? for detect screen on and screen off register a broadcast reciver like: AndroidManifest.xml: <receiver android:name="receiverScreen"> <intent

How to customize Android's LockScreen?

大城市里の小女人 提交于 2019-11-29 02:24:21
I know that there is already some apps can do this, such as: WidgetLocker Lockscreen Flyscreen I want to know how to do this in my app? What classes I can use? Or what articles I should read? I don't want to change the Android's source code. And I wonder if it will be different to deal with when the screen is locked by draw pattern? Mark Allison Have a look at this answer . You need to write your own home screen app which will implement the lockscreen behaviour that you require. There is sample code for writing your own home screen app in the Android SDK. 来源: https://stackoverflow.com

MPI with C: Passive RMA synchronization

本小妞迷上赌 提交于 2019-11-29 00:31:58
as I found no answer for my question so far and am on the edge of going crazy about the problem, I just ask the question tormenting my mind ;-) I'm working on a parallelization of a node-elimination algorithm I already programmed. Target environment is a cluster. In my parallel program I distinguish on master process (in my case rank 0) and the working slaves (every rank except 0). My idea is it, that the master is keeping track which slaves are available and send them then work. Therefore and for some other reasons I try to establish a workflow basing on passive RMA with lock-put-unlock