locking

C# sharing locks with multithreading

Is there a common way to "share" a lock between different objects operating on same set of data? I am aware that having a public object for locking is usually not recommended. For example, a Queue could be implemented as thread safe, but some other class might need a specific lock in order to lock several Queue operations. What happens...

SQL Server READPAST hint

I'm seeing behavior which looks like the READPAST hint is set on the database itself. The rub: I don't think this is possible. We have table foo (id int primary key identity, name varchar(50) not null unique); I have several threads which do, basically id = select id from foo where name = ? if id == null insert into foo (name) ...

Locking a single NSPersistentDocument

My application currently uses CoreData as a backend to store to a single SQL data file stored in ~/Library/Application Support/MYAPP/MyDataFile.sqlite. I know it's an unusual situation, but what is the best way to "lock" this file so that if the user decides (for whatever silly reason) to run a second copy of my app, Core Data won't frea...

Blocking a function call in C#

Hello All, How do I block a function call in C#? This function gets repeatedly called by different classes.I want to lock it up so that no one else can use it until I perform my current operation. Then,i want to release it again. Please help.. Thanks Edit:I'm not actually using threads...but I am using timers that call the function ...

SQL Server Latches and their indication of performance issues

I am trying to understand a potential performance issue with our database (SQL 2008) and in particular one performance counter, SQLServer:Latches\Total Latch Wait Time Total Latch Wait Time (ms). We are seeing a slow down in DB response times and the only correlating spike that I can match it with is a spike in Total Latch Wait Time and ...

How do I get the handle for locking a file in Delphi?

The LockFile API takes a file handle. I normally use TStream for file access, so I'm unsure how to get the appropriate handle, given an ANSIString filename only. My purpose is to lock a file (which may not exist originally) during a process, write some information to other users, and then unlock and delete it. I would appreciate sample...

Does creating a nonclustered index on a SQL Server 2005 table prevent selects?

I'd like to create an index on a view I have but I need to make sure the data can still be read while the index is being created. I was reading an article that suggested that when creating a nonclustered index that the data is still readable if you specify the ONLINE=ON option (example below): CREATE UNIQUE CLUSTERED INDEX CLUST_IDX_SQ...

Does Interlocked.CompareExchange(double,double,double) work in 32 bit OS?

I'm maintaining a high performance class that can be operated on by multiple threads. Many of the fields are volatile ints, and as it turns out I need to upgrade one of those to a double. I'm curious if there is a lock free way to do this, and was wondering if the Interlocked.CompareExchange(double, double, double) works as advertised ...

what will happen if not lock the dictionary when i modify it? about asp.net cache

sorry i have many questions about the lock/cache.=_=.. ->1. about cache, i know that the cache in asp.net is threadsafe, the simple code i usually use is IList<User> user= HttpRuntime.Cache["myCacheItem"] as IList<User>; if (user == null) { //should i have a lock here? //lock(some_static_var){...} Htt...

C#: Invoke Event from Locked Block

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,...

Lock whole database?

I have really odd user requirement. I have tried to explain to them there are much better ways of supporting their business process and they don't want to hear it. I am tempted to walk away but I first want to see if maybe there is another. Is there anyway that I can lock a whole database as opposed to rowlock or tablock. I know I can p...

Making Threads work in parallel in c#

I am using TcpClient object to transfer the files. There is only one object. So while transferring the file, I used to lock this object and transfer the file so the other threads waits until the TCPClient is released. Is there a way I can make Threads work in parallel with a single object? ...

2 questions on locks performance/use

Hi, On the server application, I need to assign to each connected client an unique ID, so I am doing it this way: private short GetFreeID() { lock (this.mUsedPlayerIDsSynchronization) { for (short I = 1; I < 500; I++) { if (ClientIDPool[I] == false) { ClientIDPool[I] = true...

Locking, qeue question

Today I got here nice answer that will resolve my problem. Unfortunately, I forgot to ask how about locking. The issue was simple - in the server, each connected client will get an unique ID (reusable) from 1 to 500, which is maximum of clients. The answer was to create a qeue and use waiting elements for new connections and just retur...

What to use for Thread synchronization (in c#)

Hi, currently I am using lock for sending\receiving the file from FTP through TCPClient class. But this supports only single file to send and receive. So what's the better way to use in this situation (lock, mutex, interlock, read\write lock, semaphore). ...

MySql table locking

If I have an operation as follows: begin transaction (auto commit = false) select * from foo; iterate above result set: insert into bar (insert the values from the above result set into bar); commit In the above operation will the table foo be locked until all the inserts into bar are done? Also, while the inserts are going ...

T-SQL transactions and table locking

If I want to select all records in a table that have not been processed yet and then update those records to reflect that they have been processed, I would do the following: SELECT * FROM [dbo].[MyTable] WHERE [flag] IS NULL; UPDATE [dbo].[MyTable] SET [flag] = 1 WHERE [flag] IS NULL; How do I ensure that the UPDATE works on only th...

MySQL MyISAM table locking

Does a MySQL MyISAM table gets locked when records are deleted from it? ...

Would you explain lock ordering?

I learned that I should unlock reverse order to lock order. For example. A.lock(); B.lock(); B.unlock(); A.unlock(); But, what happen if I did like this : A.lock(); B.lock(); A.unlock(); B.unlock(); I try to make a deadlock scenario, but if I always lock A earlier then B, then I don't know how deadlock would happen. Would you help me?...

Android Programming - locking application

Hi all u geeks out there... i'm a novice in Android programming though had tried my hand on blackberry... currently i was asked 4 the possibility of making an application which can control access to other applications on Android... I mean something like asking password everytime some selected apps are opened... My question is.. "is it ...