locking

C#: Invoke Event from Locked Block

我与影子孤独终老i 提交于 2019-12-05 02:25:48
问题 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, please give an example of when it would be a problem to call an event from within a lock {} block. Thanks 回答1: I don't recall ever having a need to raise an

Lock splitting vs lock striping

↘锁芯ラ 提交于 2019-12-05 02:23:24
Below is the excerpt from Effective Java by Joshua: If you do synchronize your class internally, you can use various techniques to achieve high concurrency, such as lock splitting, lock striping, and nonblocking concurrency control. Above suggests that lock splitting and lock striping are 2 different techniques but when I tried to find the difference between I couldn't find a difference. Is there is a difference between them or they are same thing? Lock splitting is about using different locks for different parts of a classes functionality; e.g. one lock for read operations and another one for

Does a lock around a write guarantee fresh read in another thread? (.Net, memory model)

十年热恋 提交于 2019-12-05 02:12:33
问题 Say I have a property whose setter is protected by a lock, but without any lock around the getter, e.g. private long _myField; public long MyProperty { get { return _myField; } set { lock(whatever) _myField = value; } } In addition to synchronizing writes (but not reads), the lock, or rather Monitor.Exit, should cause a volatile write. Let's now say we have two threads A and B, and the following sequence happens: A reads the current value of MyProperty . B writes a new value to MyProperty . A

How to remove the lock in file association in eclipse

让人想犯罪 __ 提交于 2019-12-05 01:46:40
IN Eclipse i want to chnage the default editor of some .htm files. If i try to go to FIle Association and assiciate the default editor then file gets opened in that new editor but i don't get the syntax highlighting. The solution is that the file association is locked ny some plugin editor Preferences -- Context type----text ----Your editor -- reomve the extension But i get the .htm(locked) so i cant remove it. http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-content-type.htm Note: Certain items will be marked as "locked". An item is locked if it

When are shared read locks released?

為{幸葍}努か 提交于 2019-12-05 01:28:42
When SQL Server Books online says that "Shared (S) locks on a resource are released as soon as the read operation completes , unless the transaction isolation level is set to repeatable read or higher, or a locking hint is used to retain the shared (S) locks for the duration of the transaction." Assuming we're talking about a row-level lock, with no explicit transaction, at default isolation level (Read Committed), what does " read operation " refer to? The reading of a single row of data? The reading of a single 8k IO Page ? or until the the complete Select statement in which the lock was

Advantage of upgradable readlock?

二次信任 提交于 2019-12-05 00:07:53
问题 I was wondering what are the advantages of using a upgradable read lock as opposed performing these steps: Take read lock Check condition to see if we need to take write lock Release Read Lock Take Write Lock Perform update Release Write Lock One apparent disadvantage of the performing the above steps as opposed taking an upgradable read lock is, that there is an window of time between the steps 3 and 4, where another thread can take up a write lock. Apart from this advantage what other

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

跟風遠走 提交于 2019-12-05 00:01:30
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 multiprocessing ? The threading module's synchronization primitive are lighter and faster than multiprocessing, due to the lack of dealing with shared semaphores, etc. If you are using threads; use threading's locks. Processes should use multiprocessing's locks. I would

How to understand LockService and implement it correctly?

旧巷老猫 提交于 2019-12-04 23:55:39
Summary of Code I have a Google Apps Script project that is used by around 80 users within a specific domain, however the app is executed by me (ie Publish > Deploy as web app > Execute the app as : Me ). One of the functions of the script is to populate a Google Sheet from a custom form (using HTML Service ) and then notify myself and the submitting user (who is identified through the use of a simple login system and cookies). It has been working fine for about 6 months, however on 1-2 occasions the notification email has been sent but the Google Sheet entry has not appeared. I am thinking

c# lock on reference passed to method - bad practice?

纵然是瞬间 提交于 2019-12-04 22:57:29
I have a method similar to: public static void DoSomething (string param1, string param2, SomeObject o) { //..... lock(o) { o.Things.Add(param1); o.Update(); // etc.... } } A few points: Is locking in this way bad practice? Should I lock on a private static object instead? If so, why? To minimize side effects, the object being locked on should not be the object being manipulated but rather a separate object designated for locking. Depending on your requirements, there are a few options for handling this issue: Variant A: Private locking object Choose this if you just want to ensure that

C# threading - Lock Object

谁都会走 提交于 2019-12-04 22:53:26
I am trying to lock a "boxed" object in a c# app, is this not possible? class t { System.Object t_x = new object(); public t(int p) { t_x = p; } public void w() { lock (t_x) { for (int i = 0; i < 4; i++) { { t_x = ((int)t_x) + 1; Console.WriteLine(t_x); Thread.Sleep(1000); } } } } } In another class I can start 2 threads: Thread b1 = new Thread(new ThreadStart(t1.w)); b1.Start(); Thread b2 = new Thread(new ThreadStart(t1.w)); b2.Start(); However the portion is not locked. When I lock an arbitrary object (i.e. one created and not modified as object a=new object()) it locks well. Is boxing