locking

Lock and Isolation for resource reservation pattern

让人想犯罪 __ 提交于 2019-12-22 10:37:47
问题 I need to solve a resource reservation pattern with Spring and MariaDB. The problem is very simple, I have a guest table where I store guest names of events, I have to be sure that the guest count for the event must be less or equals the maximum capacity. This is the table: create table guest( event int, name varchar(50) ) create index event on guest (event); What is the right lock procedure and isolation level for DB? Please consider that this code will run in multi-threading container. I

Lock file in Xcode 4

為{幸葍}努か 提交于 2019-12-22 10:34:03
问题 I've got a simple question. In Xcode 3 I was able to lock a file by clicking on the little lock icon at the top of each file. I'm missing this function in Xcode 4. I think I'm just blind. Can you help me? 回答1: That feature was killed (partially) in Xcode 4. Even though you can Unlock a locked file from the File menu, you cannot Lock it. Even though locking files is still possible with the Finder, it is much more troublesome when you need to lock multiple files. The long way now involves right

When to LOCK TABLES in MySQL (MyISAM tables)?

淺唱寂寞╮ 提交于 2019-12-22 10:20:16
问题 Is the internal locking of MySQL sufficient for a small to medium sized website? My tables are MyISAM. There might be a few hundred people concurrently hitting a specific table with SELECT'S and INSERT's. None of the INSERT/UPDATE queries would overlap. That is, no two users will be updating the same comment ID. INSERT's/UPDATE's would be one-off operations---there would be no reading of data and performing additional operations within the same query. Specifically, I am setting up a comment

How does the NSCondition work?

风流意气都作罢 提交于 2019-12-22 10:08:24
问题 I'm using NSCondition class in this sence: - (void) method1 { [[cocoaCondition lock] lock]; while (!someCheckIsTrue) { [cocoaCondition wait]; } // Do something. [cocoaCondition unlock]; } - (void) method2 { [cocoaCondition lock]; // Do something. someCheckIsTrue = YES; [cocoaCondition signal]; [cocoaCondition unlock]; } I have two threads, thread1 runs the method1 and thread2 runs the method2. I hope that when [cocoaCondition wait] is called, the thread1 will be blocked. Then when the thread2

Locking HttpRuntime.Cache for lazy loading

∥☆過路亽.° 提交于 2019-12-22 10:07:00
问题 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

Lockfree standard collections and tutorial or articles

时光怂恿深爱的人放手 提交于 2019-12-22 08:52:04
问题 Does someone know of a good resource for the implementation (meaning source code) of lock-free usual data types. I'm thinking of Lists, Queues and so on? Locking implementations are extremely easy to find but I can't find examples of lock free algorithms and how to exactly does CAS work and how to use it to implement those structures. 回答1: Check out Julian M Bucknall's blog. He describes (in detail) lock-free implementations of queues, lists, stacks, etc. http://www.boyet.com/Articles

Using Interlocked.CompareExchange to increment a counter until a value

倖福魔咒の 提交于 2019-12-22 08:39:20
问题 I need to increment a counter until it reaches a particular number. I can use two parallel task to increment the number. Instead of using a lock to check if the number has not reach the maximum allowed value and then incrementing, I thought using Interlocked.CompareExchange in the following manner: public class CompareExchangeStrategy { private int _counter = 0; private int _max; public CompareExchangeStrategy(int max) { _max = max; } public void Increment() { Task task1 = new Task(new Action

Locking iPhone disconnects sockets on iOS 5 only

旧街凉风 提交于 2019-12-22 08:30:40
问题 I'm working on a socket based client-server app. When a user running any iDevice on iOS 4, 4.2.1, 4.3.2, etc clicks the lock button while connected to the server, the connection remains alive. However, when I click the lock button on any device running iOS 5, the connection is immediately destroyed and upon returning to the app from the lock screen I am presented with my NSAlertView that is called when the NSStreamEventErrorOccurred method is called. I have had several clients test the app,

ReentrantLock use case

无人久伴 提交于 2019-12-22 07:18:21
问题 I am very poor in MultiThreading concepts of Java. I was going through ReentrantLock features and usage. I got that it is more flexible then synchronized and adds few more features. I can see the examples mentioned on it and I got it well. I am not able to figure out the real time scenario where exactly it will be helpful in business. I can see that it will be best to avoid deadlocks. Can some one provide the use case where without ReentrantLock it will be difficult to solve such use case. or

sql rowlock on select statement

一个人想着一个人 提交于 2019-12-22 07:02:14
问题 I have an ASP.Net webpage where the user selects a row for editing. I want to use the row lock on that row and once the user finishes the editing and updates another user can edit that row i.e. How can I use rowlock so that only one user can edit a row? Thank you 回答1: You can't lock a row like that using DB engine locks. Most other strategies would rely on keeping the connection open (such as sp_getapplock) and this is nonsensical in web apps. Even if you set a flag on the row, what happens