locking

C# release lock automatically after timeout

本秂侑毒 提交于 2019-12-13 12:33:29
问题 does anyone have any ideas on whats the best way to implement a lock so that after X number of seconds it will automatically be released ? 回答1: In web development, I cache all the time with a sliding timeout. Perhaps you could use a cached object as the lock? Here's a discussion of caching technologies in non-web applications: Caching in C# without System.Web 回答2: Assuming you are looking for an event to fire in X seconds, then I don't think there's any core Mutex object which currently

How perform SQLite query with a data reader without locking database?

元气小坏坏 提交于 2019-12-13 11:36:19
问题 I am using System.Data.Sqlite to access SQLite database in C#. I have a query which must read through rows in a table. While iterating through the rows and while the reader is open, certain SQL updates must be performed. I am running into a "database is locked" exception. The SQLite documentation states: When a process wants to read from a database file, it followed the following sequence of steps: Open the database file and obtain a SHARED lock. The documentation further states about "SHARED

lock text files with passwords [closed]

*爱你&永不变心* 提交于 2019-12-13 09:17:51
问题 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 7 years ago . Is there any way to protect the text file. I want to protect my text files to protect with password. So how is it possible that when client wants to open the text file it asks for password and files can be opened in notepad only after entering the right password. By using this can be make our files secure 回答1:

How to write getInstance method thread safe?

半城伤御伤魂 提交于 2019-12-13 09:09:36
问题 I have a getInstance method in my library which is being used in multiple threads but I am not sure whether it is thread safe: protected static DataClient instance; protected DataClient() { // do stuff here } public static synchronized void initialize() { if (instance == null) { instance = new DataClient(); } } public static DataClient getInstance() { if (instance == null) { initialize(); } return instance; } And this is the way I am using it: DataClient.getInstance(); Is this thread safe and

Why is it a good practice to have separate locks instead of having lock on object that get modified in the synchronized block in java?

99封情书 提交于 2019-12-13 07:56:54
问题 While I am going though few Java Thread tutorials I got to the following statement. It's a good practice to have separate lock objects instead of having clock on object that get modified in the synchronized block. Java underlying code optimization may create implications. What does it exactly stating? Say I have code as follows to imply the situation. public class TestSynch(){ private Object lock1; private Object lock2; private List<Integer> list1; private List<Integer> list2; public void

How efficient is a try_lock on a mutex?

本秂侑毒 提交于 2019-12-13 07:53:24
问题 How efficient is a try_lock on a mutex? I.e. how much assembler instructions are there likely and how much time are they consuming in both possible cases (i.e. the mutex was already locked before or it was free and could be locked). In case you have problems to answer the question, here is a how to (in case that is really unclear): If that answer depends a lot on the OS implementation and hardware: Please answer it for common OS`s (e.g. Linux, Windows, MacOSX), recent versions of them (in

Is this Background Thread Queue a performant implementation?

末鹿安然 提交于 2019-12-13 07:35:16
问题 Specifically, I'm wondering: Will the ManualResetEvent consume resources while it is in a wait state? Does the performance degradation of context switching apply to threads that are in a wait state? If I have a choice to use multiple BackgroundThreadQueues that do less work each, or one BackgroundThreadQueue that does more work, and I choose to use multiple...will the waiting thread queues affect process performance while they are not doing anything? Is there a better FIFO thread queue I

C# multithreaded code access to local variables inside a lock

余生长醉 提交于 2019-12-13 07:07:03
问题 My question has to do with the following bit of code. I simplified the code to distill the question. I understand that the lock keeps the foo Hashtable variable from being changed, but what about the variable outside the lock? We're seeing some odd behavior in code that looks like this and this was the question that came up. Thanks for any input. using System.Collections; namespace MultithreadScratch01 { public class ThreadFoo { public void Foo(Stub2 stub2, Hashtable foo) { Stub1 bar; var

iOS Datepicker: How to LOCK invalid dates?

狂风中的少年 提交于 2019-12-13 06:13:21
问题 I've been struggling with the maximum/minimum date lately, and honestly, I don't know what I'm missing here. I searched a lot and no one seems to complain about it. (I'm not talking about setting a maximum/minimum date as these can only make invalid dates appear gray) Here's what I've done so far: [myDatePicker addTarget:self action:@selector(disableDate) forControlEvents:UIControlEventValueChanged]; Then, on disableDate, I have something like this: if ([myDatePicker.date compare:[NSDate date

C# Multiple threads (Parallel) accessing static MySQL Connection {get;set;} with locks

*爱你&永不变心* 提交于 2019-12-13 05:42:28
问题 I have an application that runs a Parral.Foreach from a DataTable. Within that Parallel (anywhere from 3-10 parallels) the class executes either an update or select statement. I have a MySQL connection that {get;set;} see below. public static MySqlConnection Connection { get; set; } public static MySqlConnection OpenCon(string ServerAddress,int PortAddress, string UserID, string Password,int ConnectionTimeOut) { MySqlConnection masterOpenCON = new MySqlConnection("server=" + ServerAddress + "