locking

C# lock and code analysis warning CA2002

梦想与她 提交于 2019-12-05 05:09:23
In my application I have a form that starts synchronization process and for number of reasons I want to allow only one synchronization to run at a time. So I've added a static bool field to my form indicating whether sync is in progress and added a lock to set this field to true if it wasn't already set so that first thread could start synchronization but when it's running every other thread that will try to start it will terminate. My code is something like this: internal partial class SynchronizationForm : Form { private static volatile bool workInProgress; private void SynchronizationForm

multi-user application record locking - best method?

本小妞迷上赌 提交于 2019-12-05 05:00:01
问题 I'm developing a php / mysql application that handles multiple simultaneous users. I'm thinking of the best approach to take when it comes to locking / warning against records that are currently being viewed / edited. The scenario to avoid is two users viewing the record, one making a change, then the other doing likewise - with the potential that one change might overwrite the previous. In the latest versions of WordPress they use some method to detect this, but it does not seem wholly

Why is this double-checked locking correct? (.NET)

梦想的初衷 提交于 2019-12-05 04:37:08
I have read a lot about the dangers of double checked locking and I would try hard to stay away of it, but with that said I think they make a very interesting read. I was reading this article of Joe Duffy about implementing singleton with double checked locking: http://www.bluebytesoftware.com/blog/PermaLink,guid,543d89ad-8d57-4a51-b7c9-a821e3992bf6.aspx And the (variant of) solution he seemed to propose is this: class Singleton { private static object slock = new object(); private static Singleton instance; private static int initialized; private Singleton() {} public Instance { get { if

How to give priority to certain queries?

旧城冷巷雨未停 提交于 2019-12-05 04:36:05
On certain occasions, when several back-end process happen to run at the same time (queue management is something else, I can solve it like that, but this is not the question here), I get General error: 1205 Lock wait timeout exceeded; try restarting transaction ROLLING BACK The process which has less priority is the one that locks the table, due to the fact that it started a few minutes before the high priority one. How do I give priority to a query over an already running process? Hope it was clear enough. Once a query has begun execution it cannot be paused/interrupted. The only exception

Proper way to use SyncLock (in general)

让人想犯罪 __ 提交于 2019-12-05 04:27:42
This is a follow-up to a previous question regarding locking on two List(Of T) objects. The answer there was helpful but left me with another question. Suppose I have a function like this: Public Function ListWork() As Integer List1.Clear() ..Some other work which does not modify List1.. List1.AddRange(SomeArray) ..Some more work that does not involve List1.. Return List1.Count End Function which resides in a class that declares List1. In a multithreaded environment, I now understand that I should have a private locking object for List1 and lock List1 whenever it's modified or enumerated. My

What is the best way to create a lock from a web application?

徘徊边缘 提交于 2019-12-05 04:10:50
I've got a web application that re-sizes images. The re-sized images are written to disk in order to cache them. What is the best way to prevent multiple, simultaneous requests from generating the same image? A couple things to note, we have millions of images (measured in terabytes). Cached images that haven't been viewed in a while are removed. We have a web farm, but each web server has it's own local cache (the originals are stored on another server). We also place the re-sized images in a second-tier cache once they are generated so other web servers can check there to see if the image is

Are Java wait(), notify() 's implementation significantly different from locks?

淺唱寂寞╮ 提交于 2019-12-05 03:40:37
Out of curiosity, when Java implements wait() and notify() methods, are they really just using locks? i.e., wait() acquires a mutex, notify() release a mutex, notifyAll() releases all mutexes (in the same object, of course)? Other than being less cumbersome than using locks, are there other advantages of using wait() and notify()? [EDIT] I realized what I confused myself about after Brian's comments: wait doesn't lock, it releases the lock and passes it to someone else who's waiting on a synchronized statement for the mutex, then waits to be notified by someone else who has the lock and calls

How do I do an exclusive checkout in SVN?

廉价感情. 提交于 2019-12-05 03:35:12
I'm looking for a way to make an exclusive checkout from SVN. Is there a way to automatically lock a file when it's being checked out ? If one user makes an exclusive checkout, and then another user makes a checkout to the same file, how do I generate some sort of notification or an instant message to the 2nd user that the file is locked? If I understand your follow-up posts, what I think you really want is to make sure that people know about locks. I'm imagining a case where users A and B have already checked out a jpeg. User A now locks it, and you want to make sure that user B knows, so

Use Java to lock a screen

时光总嘲笑我的痴心妄想 提交于 2019-12-05 03:00:07
问题 Basically i just need to create an application (with sort of user access) which first screen is a fullscreen window that cannot be minimized or closed without entering valid username and password. Something like windows screensaver. Can it be done? What libraries should i look into? This is all i need, if my question is incomplete or unclear, feel free to ask! 回答1: Once, I wrote something in Java, out of which you can't escape. Really impossible. It is for Windows. Here you go: import java

Bug in PostgreSQL locking mechanism or misunderstanding of the mechanism

放肆的年华 提交于 2019-12-05 02:58:08
We encountered an issue with PostgreSQL 9.0.12 locking mechanism. This is our minimal code to reproduce the issue: Scenario Transaction 1 Transaction 2 BEGIN BEGIN ...... select trees for update; update apples; --passes update apples; -- stuck! reproduce code: If you want to try it in your PostgreSQL - here is a code you can copy/paste. I have a following db schema: CREATE TABLE trees ( id integer primary key ); create table apples ( id integer primary key, tree_id integer references trees(id) ); insert into trees values(1); insert into apples values(1,1); open two psql shells: on shell 1: