locking

How to lock a file on different application levels?

蹲街弑〆低调 提交于 2019-12-19 03:07:15
问题 Here's the scenario: I have a multi threaded java web application which is running inside a servlet container. The application is deployed multiple times inside the servlet container. There are multiple servlet containers running on different servers. Perhaps this graph makes it clear: server1 +- servlet container +- application1 | +- thread1 | +- thread2 +- application2 +- thread1 +- thread2 server2 +- servlet container +- application1 | +- thread1 | +- thread2 +- application2 +- thread1 +-

Boost named_mutex and remove() command

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 00:57:38
问题 I have a class which can be created by multiple threads. But at one function the code needs to be protected, so I decided to use the boost interprocess mutex. Every class creates or opens the same Mutex in it's constructor: MyClass::MyClass() { boost::interprocess::named_mutex m_Lock( boost::interprocess::open_or_create, "myLock" ); } So now there comes the point where the critical code part is called: int MyClass::MyFunction() { boost::interprocess::scoped_lock<boost::interprocess::named

File locks for linux

蓝咒 提交于 2019-12-18 21:21:13
问题 I tried using temp files: char *temp = tempnam(NULL, "myapp_"); printf("Tempname: %s", temp) // Prints /tmp/myapp_random while (1) { } But when I check /tmp (while the app is still running), the myapp_random is not there! As for using File Locks, I can't get a good grasp on it, I tried looking at <fcntl.h> but it seems to focus on locks in specified portions of a file. I just want to use the file entirely as a lock (which is why I prefer trying the temp file approach). Any ideas? 回答1: tempnam

database lock issue in HTC Desire

南笙酒味 提交于 2019-12-18 18:25:47
问题 In my application one service is getting data from server and inserting it to table A . If I go to particular UI, I need to list data from another table B if background operation is doing it will generate database locked exception. I got two database operation done in parallel each on two different table. It is working fine in samsung gt15801. But htc desire it will generate database locked error. HTC desire - insertion process takes 91 seconds. Samsung gt15801 - insertion process takes 21

How to lock SVN trunk except for merges from branch?

情到浓时终转凉″ 提交于 2019-12-18 18:04:13
问题 I'd like to prevent developers working directly on the trunk. I'm aiming to enforce all developers off the trunk and to work on there own branches until CI tests are cleared. They then have to merge from the trunk to their branch (to pick up latest changes), run and pass tests before they merge back to the trunk. Is there any rules for this style of SVN usage? 回答1: Limit trunk commits to a bot. That bot can do the conflict-free merge and commit to trunk. I've done just that; it's called

Locking Row in SQL 2005-2008

独自空忆成欢 提交于 2019-12-18 16:48:10
问题 Is there a way to lock a row in the SQL 2005-2008 database without starting a transaction, so other processes cannot update the row until it is unlocked? 回答1: You can use RowLock or other hints but you should be careful.. The HOLDLOCK hint will instruct SQL Server to hold the lock until you commit the transaction. The ROWLOCK hint will lock only this record and not issue a page or table lock. The lock will also be released if you close your connection or it times out. I'd be VERY careful

Synchronized stored procedure execution in mysql

强颜欢笑 提交于 2019-12-18 15:54:56
问题 I have a stored procedure in mysql thats to perform a task that needs to be synchronized such that if two application calls the stored procedure, only one can access a section of code to perform the task, keeping the other one to get blocked until the first one finishes the task. DELIMITER $$ CREATE PROCEDURE SP_GEN_ID(IN NAME VARCHAR(20)) BEGIN DECLARE maxLen int default 0; START TRANSACTION; #the section of code that needs to be synchronized COMMIT END; $$ DELIMITER ; So, if two

Why should you lock threads?

左心房为你撑大大i 提交于 2019-12-18 15:53:40
问题 I've read a lot of examples on locking threads.. but why should you lock them? From my understanding, when you initiate threads without joining them, they will compete with the main thread and all other threads for resources and then execute, sometimes simultaneously, sometimes not. Does locking ensure that threads DON'T execute simultaneously? Also, what wrong with threads executing simultaneous? Isn't that even better? (faster overall execution) When you lock threads, will it lock them all

Can I put a return statement inside a lock

守給你的承諾、 提交于 2019-12-18 14:40:33
问题 Dupe: return statement in a lock procedure: inside or outside The title is a little misleading. I know that you can do it, but I'm wondering about the performance implications. consider these two blocks of code. (no error handling) This block has the return outside of the lock public DownloadFile Dequeue() { DownloadFile toReturn = null; lock (QueueModifierLockObject) { toReturn = queue[0]; queue.RemoveAt(0); } return toReturn; } This block has the return statement within the lock public

Using Timeout to avoid deadlock in Java multithreading

无人久伴 提交于 2019-12-18 13:19:14
问题 One of the strategy to avoid deadlock situation in Java Multithreading is using timeout. Suppose, one thread has acquired lock on one resource and now waiting for lock on another resource. After certain time period if it can not acquire lock on resource2 then it should stop waiting for lock on resource2. Also it should release lock on resource1. Thus deadlocks will be avoided. But how to implement it in Java ? How to explicitly "release" lock ? How to define timeout to wait for lock. What is