locking

SQLServer lock table during stored procedure

扶醉桌前 提交于 2019-12-05 20:31:46
问题 I've got a table where I need to auto-assign an ID 99% of the time (the other 1% rules out using an identity column it seems). So I've got a stored procedure to get next ID along the following lines: select @nextid = lastid+1 from last_auto_id check next available id in the table... update last_auto_id set lastid = @nextid Where the check has to check if users have manually used the IDs and find the next unused ID. It works fine when I call it serially, returning 1, 2, 3 ... What I need to do

Locking HttpRuntime.Cache for lazy loading

寵の児 提交于 2019-12-05 20:04:25
We have a website running .NET 2.0 and have started using the ASP.Net HttpRuntime.Cache to store the results of frequent data lookups to cut down our database access. Snippet: lock (locker) { if (HttpRuntime.Cache[cacheKey] == null) { HttpRuntime.Cache.Insert(cacheKey, GetSomeDataToCache(), null, DateTime.Today.AddDays(1), Cache.NoSlidingExpiration); } return ((SomeData)HttpRuntime.Cache[cacheKey]).Copy(); } We are pessimistically locking whenever we want to look at the cache. However, I've seen various blogs posted around the web suggesting you lock after you check the cache value instead, to

What is equivalent of the C# lock statement in PHP?

自闭症网瘾萝莉.ら 提交于 2019-12-05 19:24:17
For concurrency and ensuring the integrity of the data, how would you obtain a mutual-exclusion lock for a given object? Would you need to use locking within the database, or a file, or does PHP support something like this? PHP doesn't support multithreading so there's no locking mechanism for objects. If you want to lock a file you could use flock for that. There's no need to lock database as database engines usually can handle multiple connections. Bare in mind PHP is not multithreaded, so it's unlikely you need anything like this... however, may be needed if you use shared memory, or any

How can I validate an image file in Perl?

霸气de小男生 提交于 2019-12-05 19:16:21
How would I validate that a jpg file is a valid image file. We are having files written to a directory using FTP, but we seem to be picking up the file before it has finished writing it, creating invalid images. I need to be able to identify when it is no longer being written to. Any ideas? Easiest way might just be to write the file to a temporary directory and then move it to the real directory after the write is finished. Or you could check here . JPEG::Error [arguments: none] If the file reference remains undefined after a call to new, the file is to be considered not parseable by this

c# Thread Safe Deep Copy

安稳与你 提交于 2019-12-05 19:10:45
问题 I have been reading alot of the other questions as well as alot of google searches and I've been unable to find a clear solution. Based on some best practices I've read, the static methods of a class should be created thread safe, and the instance members should leave thread safety to the consumers. I would like to implement a deep copy method for the class. The class itself has other reference type members. Is there any way to make the deep copy method thread safe without having to impose

Locking mechanisms for shared-memory consistency

梦想与她 提交于 2019-12-05 19:00:13
问题 I'm developing a mechanism for interchanging data between two or more processes using shared memory on linux. The problem is some level of concurrency control is required to maintain data integrity on the shared memory itself, and as I'm specting that sometime or another my process could be killed/crash, common lock mechanisms dont' work because they could left the memory in a "locked" state and right after dying, making other processes hung waiting for the lock to be released. So, doing some

What's blocking “Select top 1 * from TableName with (nolock)” from returning a result?

江枫思渺然 提交于 2019-12-05 16:46:15
问题 I'm currently running the following statement select * into adhoc..san_savedi from dps_san..savedi_record It's taking a painfully long time and I'd like to see how far along it is so I ran this: select count(*) from adhoc..san_savedi with (nolock) That didn't return anything in a timely manner so for the heck of it I did this: select top 1 * from adhoc..san_savedi with (nolock) Even that seems to run indefinitely. I could understand if there are millions of records that the count(*) could

Is there any idiomatic explicit use of mutex::lock() or unlock()?

折月煮酒 提交于 2019-12-05 16:11:30
The recommended way to use a mutex for locking a critical region of code is via RAII, i.e. mutex_type mutex; { // start of critical region std::lock_guard<mutex_type> lock(mutex); // first statement in critical region // ... do critical stuff, may throw an exception } // end of critical region so that when an exception is thrown within the critical region, the mutex will still be unlocked (by the destructor of std::lock_guard ). However, this way the members mutex::lock() and mutex::unlock() are never explicitly called by user code. Q What, if any, is the major idiomatic explicit use of mutex:

C# file is being used by another process

天大地大妈咪最大 提交于 2019-12-05 14:32:59
I am not sure how can I solve my problem. From time to time I get the error: "The process cannot access the file 'xxxx' because it is being used by another proces". Here is my method where the error happens: private static void write_history(int index, int time_in_sec, int[] sent_resources) { string filepath = "Config\\xxx.txt"; int writing_index = 0; if (File.Exists(filepath)) { System.Threading.Thread.Sleep(5000); StreamReader reader = new StreamReader(new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read)); string temp = reader.ReadToEnd(); reader.Close(); for (int i = 0;

In Hazelcast, is it possible to use clustered locks that do _not_ care about the local thread that performs the lock/unlock operations?

吃可爱长大的小学妹 提交于 2019-12-05 14:19:50
Hazelcast locks (such as http://www.hazelcast.com/docs/1.9.4/manual/multi_html/ch02s07.html ) as I understand it behave the same way as the Java concurrency primitives but across the cluster. The makes it possible to use to synchronize between thread in the local process as well as over the cluster. However, is there any way I can opt out of this behaviour? In my current project, I need a way of coordinating unique ownership of a resource across the cluster but want to aquire and release this ownership from multiple points in my application - can I do this in some way that does not involve