locking

How to measure lock contention?

I'm reading http://lse.sourceforge.net/locking/dcache/dcache%5Flock.html, in which spinlock time for each functions is measured: SPINLOCKS HOLD WAIT UTIL CON MEAN( MAX ) MEAN( MAX )(% CPU) TOTAL NOWAIT SPIN RJECT NAME 5.3% 16.5% 0.6us(2787us) 5.0us(3094us)(0.89%) 15069563 83.5% 16.5% 0% dcache_...

how to force a lock to be obtained in SQL Server?

Hello, I am working on making an application run on both Postgres and SQL Server. in PostgreSQL you can do something like lock mytable exclusive; which would keep the entire table from being written to(insert/updated). I need the entire table to be locked while certain things are updated(and RIDs can not be changed or else it'll scre...

MySQL UPDATE statement batching to avoid massive TRX sizes

I am often writing datascrubs that update millions of rows of data. The data resides in a 24x7x365 OLTP MySQL database using InnoDB. The updates may scrub every row of the table (in which the DB ends up acquiring a table-level lock) or may just be scrubbing 10% of the rows in a table (which could still be in the millions). To avoid ...

When the property is getted in a ForEach loop?

Hello, I have a property getter with a lock like this one: Public ReadOnly Property ActiveClientList() as List(Of TcpClient) Get SyncLock(m_activeClientListLock) Return m_activeClientList End SyncLock End Get End Property When I do a ForEach loop when is the property getted? I mean, in this loop wh...

Is there any reason to use threading.Lock over multiprocessing.Lock?

If a software project supports a version of Python that multiprocessing has been backported to, is there any reason to use threading.Lock over multiprocessing.Lock? Would a multiprocessing lock not be thread safe as well? For that matter, is there a reason to use any synchronization primitives from threading that are also in multiproce...

How to stop one thread until n threads have completed their work.

Hello, I have an application with one main thread and N worker threads. At some point I need that the main thread waits until all the N threads have completed one section of their work. I normally would use Monitor.Wait() and Monitor.Pulse() but this will prevent the N threads from working at the same time. Any idea on how to do that?...

What exactly means locking on an object?

Hi, Altough I am using locks in my app, I do not understand what exactly does locking on particular reference type. I thought it just stops the thread until the content of {} is finished. But I have read that locking(this) is bad, if its public - why? The article explained it but I do not understand sice I do not know what happened to th...

how can i lock tables in MySQL or phpmyadmin?

I need to use a table for a queuing system. The table will be constantly be updated. For example, multiple users on my website, will add their files for process, and I heard that when updates occur simultaneously from multiple users, the table becomes non responsive or something like that. so do I need locking tables in this situation...

Intermittent log4net RollingFileAppender locked file issue

We are seeing an intermittent issue on development and production machines whereby our log files are not getting logged to. When running in development and debugging using Visual Studio we get the following log4net error messages in the VS output window: log4net:ERROR [RollingFileAppender] Unable to acquire lock on file C:\folder\file....

Doing an atomic update of the first instance in a QuerySet

I'm working on a system which has to handle a number of race-conditions when serving jobs to a number of worker-machines. The clients would query the system for jobs with status='0' (ToDo), then, in an atomic way, update the 'oldest' row with status='1' (Locked) and retrieve the id for that row (for updating the job with worker informat...

Does lock create a pile-up of threads? / Is this a correct way to avoid a lock

I have a program which receives data from unmanaged code about 500 to 700 times per second. Some of this data is usefull and needs to be processed and some of it is useless and get disgarded right away. To find out if received data is usefull I use a List of strings. My problem/question is: when I use a lock on the List to delete some or...

How to do locking in SQL Server like MYSQL

Hi all, I'm converting a webapp from mysql to SQL Server. Now I want to convert the following code (this is a simplified version): LOCK TABLES media WRITE, deleted WRITE; INSERT INTO deleted (stuff) SELECT stuff FROM media WHERE id=1 OR id=2; DELETE FROM media WHERE id=1 OR id=2; UNLOCK TABLES; Because I'm copying stuff which is goin...

When to use lock vs MemoryBarrier in .NET

In .NET the lock keyword is syntactic sugar around Monitor.Enter and Monitor.Exit, so you could say that this code lock(locker) { // Do something } is the same as Monitor.Enter(locker); try { // Do Something } finally { Monitor.Exit(locker); } However the .NET framework also includes the MemoryBarrier class which works in a s...

SQL server transactions in PHP

I'm trying to grasp the idea of transactions fully. Therefore the following question... (ofcourse newbie, so don't laugh :D ) I have set up a (simplified) transaction in PHP (using the PHP SQL driver from microsoft). I want to get the rows I'm going to delete for some extra processing later: sqlsrv_begin_transaction($conn); $sql = "SEL...

How to implement a critical section in CUDA?

I'm trying to implement a critical section in CUDA using atomic instructions, but I ran into some trouble. I have created the test program to show the problem: #include <cuda_runtime.h> #include <cutil_inline.h> #include <stdio.h> __global__ void k_testLocking(unsigned int* locks, int n) { int id = threadIdx.x % n; while (atomi...

C# Why is my lock statement hanging?

I have followed some tutorials on how to create custem event accessors. This is the code I have: event ControlNameChangeHandler IProcessBlock.OnControlNameChanged { add { lock (ControlNameChanged) { ControlNameChanged += value; } } remove { lock (ControlNameChanged) ...

set CONTEXT_INFO select context_info(), locking

Imagine a Table T that is used as follows: At time T0: SPID 1: begin transaction ... insert into T(...) values(...); ... commit; At time T1 SPID 2: begin transaction select * from T where C=cval; ... commit; Assume transaction isolation level set to serializable. Also Assume that SPID1 manages to take TABLOCKX on T ...

Java, C++, NIO, mmaped buffer, synchronization

Exposition: I am on Linux / Mac. Part of my code is in Java, part of my code is in C++. They both have the same file mmapped for fast communication. I want to synchronize the Java & C++ code. I know the following: 1) given two threads in Java, I can use Locks / monitors. 2) given one piece of code in Java, one in C++, I can have t...

Is a lock necessary in this situation?

Is it necessary to protect access to a single variable of a reference type in a multi-threaded application? I currently lock that variable like this: private readonly object _lock = new object(); private MyType _value; public MyType Value { get { lock (_lock) return _value; } set { lock (_lock) _value = value; } } But I'm wonderin...

Java File Locking

I have several threads (some of which are spawned by Process X, others by Process Y, et cetera), and each thread needs to write to a file MyFile. However, if Thread T1 starts writing to MyFile first, then, when Thread T2 starts writing, it needs to wait for T1 to release the file, so that it can read the contents that were written in Thr...