locking

How to lock/unlock a file across process?

耗尽温柔 提交于 2021-02-08 14:22:24
问题 Using C# running on mono on Linux, notice that below code works well on windows can lock a file across process but not on linux via mono (ubuntu 14.04) new FileStream("myfile.lock",FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None); research from internet, i should be able to do it with advisory lock FileStream.Lock however, it doesn`t work. tested with two processes on ubuntu 14.04, both of them can execute "FileStream.Lock(0, int.MaxValue)". i would expect the later one will fail

Minimal-locking thread-safe hashtable?

白昼怎懂夜的黑 提交于 2021-02-08 14:19:21
问题 Are there any available implementations of a Hashtable that provide thread safety with minimal locking in .NET? Or in another language that can be ported to .NET? We're looking for something in between using a BCL Dictionary<,> class with lock() and a distributed caching application like memcached or Velocity. The intended use is for a cache with thousands of readers reading out immutable values based on keys (either numbers or guids, we haven't decided which yet). There will be far less

Function to get exclusive lock in SQLite

你说的曾经没有我的故事 提交于 2021-02-08 09:39:14
问题 I was trying to get the exclusive lock for the SQLite database. I used sqlite3_db_mutex(db); and sqlite3_mutex_try(mutexObj) function to acquire lock, but when I tried to execute query from other shell to the same database, I was able insert row in the table,read the data from table I want is to get the LOCK to the database, so that during that time, no-one can make any change to the database, while I've acquired the lock. It is possible in Sqlite ???? 回答1: sqlite3_db_mutex locks that

Multi-threading concept and lock in c#

纵饮孤独 提交于 2021-02-08 08:16:48
问题 I read about lock, though not understood nothing at all. My question is why do we use a un-used object and lock that and how this makes something thread-safe or how this helps in multi-threading ? Isn't there other way to make thread-safe code. public class test { private object Lock { get; set; } ... lock (this.Lock) { ... } ... } Sorry is my question is very stupid, but i don't understand, although i've used it many times. 回答1: Accessing a piece of data from one thread while other thread is

How to modify each section of a vector in multiple threads [duplicate]

╄→尐↘猪︶ㄣ 提交于 2021-02-08 08:01:30
问题 This question already has answers here : How do I pass disjoint slices from a vector to different threads? (1 answer) How can I pass a reference to a stack variable to a thread? (1 answer) How to get mutable references to two array elements at the same time? (6 answers) Closed 2 years ago . I have a vector of u8 and I need to fill this vector with values that can be computed in parallel: let vector: Vec<u8> = vec![0, len]; Given n_threads threads, each thread can take care of a section of the

How to modify each section of a vector in multiple threads [duplicate]

不打扰是莪最后的温柔 提交于 2021-02-08 08:01:27
问题 This question already has answers here : How do I pass disjoint slices from a vector to different threads? (1 answer) How can I pass a reference to a stack variable to a thread? (1 answer) How to get mutable references to two array elements at the same time? (6 answers) Closed 2 years ago . I have a vector of u8 and I need to fill this vector with values that can be computed in parallel: let vector: Vec<u8> = vec![0, len]; Given n_threads threads, each thread can take care of a section of the

Is it safe to use a boxed value type as a locker for the lock statement?

无人久伴 提交于 2021-02-08 04:58:32
问题 The documentation of the lock statement is pretty straightforward: lock (x) { // Your code... } where x is an expression of a reference type . So I should not be allowed to pass a value type as locker for a lock . I noticed though that I can use a value type that implements an interface. In other words I can do this: IDisposable locker = default(DisposableStruct); lock (locker) Console.WriteLine("Thread safe"); struct DisposableStruct : IDisposable { public void Dispose() { } } This was

Why Do Locks Require Instances In C#?

妖精的绣舞 提交于 2021-02-07 20:57:30
问题 What is the purpose of using an object instance for each lock object? Is the CLR storing an instance of an object passed by a thread on a call to Monitor.Enter(instance) so that when another thread tries to enter a lock, the CLR will check the instance provided by the new thread and if the instance matches to the first threads instance then the CLR will add the new thread to a first in first served queue and so on? 回答1: Is the CLR storing an instance of an object passed by a thread on a call

Why Do Locks Require Instances In C#?

女生的网名这么多〃 提交于 2021-02-07 20:55:15
问题 What is the purpose of using an object instance for each lock object? Is the CLR storing an instance of an object passed by a thread on a call to Monitor.Enter(instance) so that when another thread tries to enter a lock, the CLR will check the instance provided by the new thread and if the instance matches to the first threads instance then the CLR will add the new thread to a first in first served queue and so on? 回答1: Is the CLR storing an instance of an object passed by a thread on a call

Thread locking when flushing jsp file

六眼飞鱼酱① 提交于 2021-02-07 12:51:58
问题 Under heavy load I see lot of threads getting locked when GZipping and decompressing the JSP file. The thread dump looks like below. Seems to be coming from "header.jsp" which is of size 14Kb. http-0.0.0.0-8080-304" daemon prio=3 tid=0x0000000008bcc000 nid=0x302 runnable [0xfffffd7de7bc2000] java.lang.Thread.State: RUNNABLE at java.util.zip.Deflater.deflateBytes(Native Method) at java.util.zip.Deflater.deflate(Deflater.java:306) - locked <0xfffffd7e589078e8> (a java.util.zip.ZStreamRef) at