locking

Android 4.3 : How can I check if user has lock enabled?

心不动则不痛 提交于 2019-12-09 13:03:09
问题 I want my app to behave differently (not store stuff) if the user does not have a lock screen or only swipe enabled. The top answer here: check whether lock was enabled or not has been edited to say the code no longer works after upgrade to Android 4.3. Is there anyway to detect this on Android 4.3? 回答1: Ok, so it seems it is possible with some reflection. Not the best solution, but at least it works on the devices we tried: Class<?> clazz = Class.forName("com.android.internal.widget

Swapping a running jar at runtime

試著忘記壹切 提交于 2019-12-09 12:59:41
问题 I am building an update system in which I need to be able to replace a referenced jar of a running application jar at runtime. However, I am running into file locking issues on Windows when trying to perform file utility functions on the jar such as 'setLastModified'. After some googling I found this snippet... What I found in my research is that the standard ClassLoader implementation never closes a jar file once it has been opened. It also only loads resources from the jar file as needed.

Platform independent file locking?

风流意气都作罢 提交于 2019-12-09 12:11:41
问题 I'm running a very computationally intensive scientific job that spits out results every now and then. The job is basically to just simulate the same thing a whole bunch of times, so it's divided among several computers, which use different OSes. I'd like to direct the output from all these instances to the same file, since all the computers can see the same filesystem via NFS/Samba. Here are the constraints: Must allow safe concurrent appends. Must block if some other instance on another

C# Am i using lock correctly?

随声附和 提交于 2019-12-09 12:08:16
问题 I'm currently trying to write a thread-safe logger class. I'm not very familiar with correct design and best practices in this area. Is there a flaw in my code? public class WriteStuff { private readonly StreamWriter m_Writer; private readonly object m_WriteLock = new object (); public WriteStuff(String path) { m_Writer = File.CreateText (path); m_Writer.WriteLine ("x"); m_Writer.Flush (); } public void ListenTo(Foo foo) { foo.SomeEvent += new EventHandler<SomeArgs> (Foo_Update); } private

Timeout on advisory locks in postgresql

蓝咒 提交于 2019-12-09 09:03:43
问题 I'm migrating from ORACLE. Currently I'm trying to port this call: lkstat := DBMS_LOCK.REQUEST(lkhndl, DBMS_LOCK.X_MODE, lktimeout, true); This function tries to acquire lock lkhndl and returns 1 if it fails to get it after timeout seconds. In postgresql I use pg_advisory_xact_lock(lkhndl); However, it seems that it waits for lock forever. pg_try_advisory_xact_lock returns immediately if fails. Is there a way to implement timeout version of lock acquiring? There is lock_timeout setting, but I

Is locking access to a bool required or is it Overkill

戏子无情 提交于 2019-12-09 08:39:38
问题 I have a class that is designed primarily as a POCO class, with various Threads and Tasks could read its values, and only others only occasionally updating these values. This seems to be an ideal scenario for ReaderWriterLockSlim. The question is, in the class, if the property that needs to be thread-safe, if the property is a bool, is that overkill? what happens if it is an int? DateTime? public class MyClass { private bool _theValue = false; private ReaderWriterLockSlim _theValueLock = new

What is the equivalent for LOCK_ESCALATION = TABLE in SQL Server 2005?

拜拜、爱过 提交于 2019-12-09 07:30:35
问题 I have a script that was generated in SQL Server 2008, but I need to execute it against a SQL Server 2005 database. What would an equivalent statement for the following be in SQL Server 2005? ALTER TABLE dbo.Event SET (LOCK_ESCALATION = TABLE) 回答1: LOCK_ESCALATION = TABLE is the default behavior in SQL Server 2008 & is the ONLY behaviour in SQL Server 2005. You can safely drop the statement without any change in functionality. 回答2: There is no equivalent option: it's new in SQL Server 2008.

lock-free calc: how to sum N double numbers that are changing by other threads?

◇◆丶佛笑我妖孽 提交于 2019-12-09 07:30:28
upd: Let me rephrase my question shortly. There are N double numbers. There are N dedicated threads each of them update own double number ( _cachedProduct in the example below). Somehow I need to have sum of these numbers and I need IndexUpdated event to be raised ASAP after any double number is changed (it would be nice if such event can be raised in 10 µs or less). Below is how I tried to implement this task =============================================== To calculate stock exchange index I create private double[] _cachedProduct; field. These field is written by many threads // called from

Can I limit concurrent invocations of an AWS Lambda?

不问归期 提交于 2019-12-09 07:24:33
问题 I have a Lambda function that’s triggered by a PUT to an S3 bucket. I want to limit this Lambda function so that it’s only running one instance at a time – I don’t want two instances running concurrently. I’ve had a look through the Lambda configuration and docs, but I can’t see anything obvious. I can about writing my own locking system, but it would be nice if this was already a solved problem. How can I limit the number of concurrent invocations of a Lambda? 回答1: AWS Lambda now supports

lock inside lock

蓝咒 提交于 2019-12-09 07:23:13
问题 I'm wondering if this construction will cause an error: lock(sync) { // something lock(sync) { //something lock(sync) { //something } } } I've run this code, and it seems fine, but maybe in some circumstances an error may be thrown? 回答1: lock is a wrapper for Monitor.Enter and Monitor.Exit: The lock keyword calls Enter at the start of the block and Exit at the end of the block. From the former's documentation: From the documentation for Monitor.Enter: It is legal for the same thread to invoke