35
голосов
6ответов
31858 просмотров

Optimal lock file method

Windows has an option to open a file with exclusive access rights. Unix doesn't. In order to ensure exclusive access to some file or device, it is common practice in Unix to use a lock file usually stored in the /var/lock directory. The C instruction open( "/var/lock/myLock.lock", O_RDWR | O_...

2
голосов
2ответов
605 просмотров

Locking hierarchy of objects in .NET

I have a class that represents the "state of the world". The class has many collections of many other objects which in turn have references to more objects and collections of objects, sometimes even references to their ancestors in the "world hierarchy". To simplify what's being said, here is an ...

7
голосов
2ответов
11432 просмотров

How can I lock the screen using C#?

I just write my first C# application, which is a scheduler. Once an hour I want to pop-up a dialog and lock the screen for two minutes in order to take a break. As of now, my application just shows a form on "TopMost" when its time to break and hides it two minutes later. How can I lock the sc...

1
голосов
2ответов
243 просмотров

Bad Fairness with a ReadWriteLock / SharedLock under load

we are currently designing a multithreaded server application. To optimize performance, we decided to implement a ReadWriteLock, i.e. multiple threads can get a lock if they only want to read but just one thread may hold the write lock. This lock is used with a list and iterating over the list ...

0
голосов
2ответов
46 просмотров

Strategies to issue unique records via db?

We have more than 1 instances of a certain exe running from different locations. An exe is supposed to fetch a set of records and do some work based on them. The set of records fetched from exe A should not be fetched by exe B and vice versa. Exes A & B are the same exes; they are running fro...

4
голосов
5ответов
15883 просмотров

Is a read lock on a ReentrantReadWriteLock sufficient for concurrent reading of a RandomAccessFile

I'm writing something to handle concurrent read/write requests to a database file. ReentrantReadWriteLock looks like a good match. If all threads access a shared RandomAccessFile object, do I need to worry about the file pointer with concurrent readers? Consider this example: import java.io.F...

1
голосов
2ответов
99 просмотров

Are partially updated values when multithreading still a concern on modern CPUs?

From the Wikipedia article on Read-Copy-Update: The reason that it is safe to run the removal phase concurrently with readers is the semantics of modern CPUs guarantee that readers will see either the old or the new version of the data structure rather than a partially updated reference. Is...

18
голосов
4ответов
3933 просмотров

Do atomic operations become slower as more CPUs are added?

x86 and other architectures provide special atomic instructions (lock, cmpxchg, etc.) that allow you to write 'lock free' data structures. But as more and more cores are added, it seems as though the work these instructions will actually have to do behind the scenes will grow (at least to maintai...

1
голосов
2ответов
2114 просмотров

Should an NSLock instance be "global"?

Should I make a single NSLock instance in the application delegate, to be used by all classes? Or is it advisable to have each class instantiate its own NSLock instance as needed? Would the locking work in the second case, if I, for example, had access to a managed object context that is spread...

2
голосов
1ответов
4709 просмотров

PHP, mysqli, and table locks?

I have a database table where I need to pull a row, test user input for a match, then update the row to identify the user that made the match. Should a race condition occur, I need to ensure that the first user's update is not overwritten by another user. To accomplish this I intend to: 1. Read...

4
голосов
1ответов
5157 просмотров

"System lock" in MySQL + MyISAM

I noticed that 'show processlist' on our MySQL server indicates a lot of threads in 'System lock' state, often followed by just 'Locked', the latter which I'd expect since we have some selects locking behind an update/insert on a MyISAM table. But 'System lock' shows up a lot more than just 'Loc...

3
голосов
3ответов
6396 просмотров

How to Open a CSV or XLS with Jet OLEDB and attain Table Lock?

I am trying to figure out how to read/write lock a CSV or XLS file when I read it as a Database via Jet OLEDB. The following code will open a CSV as a DB and load it into a DataTable object: private DataTable OpenCSVasDB(string fullFileName) { string file = Path.GetFi...

28
голосов
1ответов
2746 просмотров

Is the volatile keyword required for fields accessed via a ReentrantLock?

My question refers to whether or not the use of a ReentrantLock guarantees visibility of a field in the same respect that the synchronized keyword provides. For example, in the following class A, the field sharedData does not need to be declared volatile as the synchronized keyword is used. cl...

1
голосов
5ответов
276 просмотров

C++ inheritence for on-stack objects

I have a base class, Token. It has no implementation and as such acts as a marker interface. This is the type that will be used by callers. { Token t = startJob(jobId); // ... (tasks) // t falls out of scope, destructors are called } I have a derived class, LockToken. It wraps arou...

4
голосов
2ответов
7664 просмотров

Locking and unlocking files using the java API

One of our clients is using some Novel security software that sometimes locks some .class files that our software creates. This causes some nasty problems for them when this occurs and I am trying to research a workaround that we could add to our error handling to address this problem when it co...

2
голосов
3ответов
869 просмотров

How should I make my hashtable cache implementation thread safe when it gets cleared?

I have a class used to cache access to a database resource. It looks something like this: //gets registered as a singleton class DataCacher<T> { IDictionary<string, T> items = GetDataFromDb(); //Get is called all the time from zillions of threads internal T Get(string ke...

37
голосов
4ответов
84857 просмотров

java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for

Why may this happen? The thing is that monitor object is not null for sure, but still we get this exception quite often: java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for (tIdx=60) at java.lang.Object.wait(Object.java:474) at ... The code that provokes ...

1
голосов
5ответов
253 просмотров

Concurrency issues while accessing data via reflection in C#

I'm currently writing a library that can be used to show the internal state of some running code (mainly fields and properties both public and private). Objects are accessed in a different thread to put their info into a window for the user to see. The problem is, there are times while I'm walkin...

2
голосов
2ответов
3285 просмотров

Non-intrusively unlock file on Windows

Is there a way to unlock a file on Windows with a Python script? The file is exclusively locked by another process. I need a solution without killing or interupting the locking process. I already had a look at portalocker, a portable locking implementation. But this needs a file handle to unlock...

8
голосов
3ответов
11182 просмотров

Check if an application is idle for a time period and lock it

In my project I need an application lock (same as windows lock). If the application is idle for a time period the application should be locked i.e, the login window for the application will appear. How can I do it in a WPF C# application?

0
голосов
1ответов
186 просмотров

Process Lock Code Illustration Needed

I recently started this question in another thread (to which Reed Copsey graciously responded) but I don't feel I framed the question well. At the core of my question, I would like an illustration of how to gain access to data AS it is being get/set. I have Page.aspx.cs and, in the codebehind...

4
голосов
2ответов
5802 просмотров

DataReader Behaviour With SQL Server Locking

We are having some issues with our data layer when large datasets are returned from a SQL server query via a DataReader. As we use the DataReader to populate business objects and serialize them back to the client, the fetch can take several minutes (we are showing progress to the user :-)), but w...

5
голосов
3ответов
2401 просмотров

What happens if I lock an object while another thread use that variable?

I am not sure how lock works. What happens if I have a List<T> list and 2 threads ? What happens if thread1 start running first and enumerate that list foreach(T t in list) { // code } and in the same time, but after thread1 has started, thread2 will lock the list lock(list) { // c...

2
голосов
2ответов
962 просмотров

HttpApplicationState - Why does Race condition exist if it is thread safe?

I just read an article that describes how HttpApplicationState has AcquireRead() / AcquireWrite() functions to manage concurrent access. It continues to explain, that in some conditions however we need to use an explict Lock() and Unlock() on the Application object to avoid a Race condition. I ...

32
голосов
2ответов
41939 просмотров

What effect does HOLDLOCK have on UPDLOCK?

I have seen many examples of the HOLDLOCK hint being used in combination with UPDLOCK (like this). However Microsoft's documentation for these hints make it seem like HOLDLOCK should be redundant, since UPDLOCK already persists the lock until the end of the transaction. (Also it seems to say that...

0
голосов
2ответов
3252 просмотров

Is it possible in DB2 or in any Database to detect if the table is locked or not?

Is it possible in DB2 to detect if the table is locked or not. Actually whenever we use Select statement and if that table is locked [ may be because of on going execution of insertion or deletion ] , then we have to wait till the table is unlocked. In our application sometimes it goes to even ...

10
голосов
1ответов
6031 просмотров

How do I lock the console across threads in C#.NET?

I have a logger class that handles various information display with pretty colors (yay.). However, since it writes to the console in separated steps (i.e. set color to red, write text, set color to gray, write text, for something that would render "[Error] Description..." with the error being in ...

2
голосов
1ответов
1893 просмотров

--single-transaction --lock-tables options of mysqldump- what happens internally?

I did find other posts similar to this, but wanted a little extra information on these options of mysqldump. I have understood that the --single-transaction and --lock-tables are mutually exclusive operations. Following are my questions regarding these options. a) Suppose I have chosen to use --...

19
голосов
4ответов
124917 просмотров

How to check if a table is locked in sql server

I have a large report I am running on sql server. It takes several minutes to run. I don't want users clicking run twice. Since i wrap the whole procedure in a transaction, how do I check to see if the table is locked by a transaction? If so I would want to return an error message saying "report ...

5
голосов
2ответов
211 просмотров

understanding Locking help?

I'm creating an ASP.net website which handles thousands of requests and it all stems from one main object that they all share to read it. I'm trying to wrap my head around these different types of locks. Some common questions i have for each. What is the scope of each lock Application, Session...