locking

Why should I use SpinWait?

北战南征 提交于 2019-12-25 05:31:07
问题 I have written two lock-free update helper methods inspired by Joseph Albahari & Marc Gravell Looking at the 2nd implementation why would I need the SpinWait in the 1st implementation? What are the advantables/disadvantages of one over the other? Please note this question is not about what SpinWait does but rather specific to how these two methods differ in execution. public static void LockFreeUpdate1<T>(ref T field, Func<T, T> updater) where T : class { var spinner = new SpinWait(); T

Preventing a file from deletion and change

放肆的年华 提交于 2019-12-25 04:01:59
问题 I have a text file. I need to the following: 1. Prevent remove a file. 2. Prevent changes to the file. Even if the program is not running. Is this possible? Maybe through the use of the service? Users of application can add new data to a file. General: I need to prevent my file from delete and any changes (outside of my app). Thanks. 回答1: This would be something you do with file permissions. Inside of the files security settings, you can set who can delete the file, who can modify the file,

How to create a file lock on any txt, php, css or other filetypes on Linux Ubuntu?

与世无争的帅哥 提交于 2019-12-25 04:00:13
问题 At the office, we're a few developers working on the same projets all the time. Sometimes, we're modifying a file (PHP or CSS or JS or ...) and we don't know if someone else is modifying the same file at the same time. Of course we're using GIT for larger projects but when it's a small project we just do it on our local server. I was thus wondering if there was some kind of lock, similar to what we have with an Openoffice document where when the file is open on a computer and another computer

Locking User account created under Windows Authentication in SQL Server

。_饼干妹妹 提交于 2019-12-25 02:59:25
问题 As per my project requirement i need to lock a user in SQL Server(Which is created using Windows Authentication). Is there any way to do this? For example: For a SQL login if you try to login using wrong Password more than 3 or 4 attempts, then that account gets locked out. User cannot login to SQL Server using this username. I want to check this using Users created under windows authenntication Thanks for the help Santhosh 回答1: You need to keep two things apart: on a server-level , you have

Property with Volatile or Lock

好久不见. 提交于 2019-12-25 02:08:52
问题 I have a property with a backing field which I want to make thread safe (get and set). The get and set method has no logic except the setting and returning. I think there are two ways to capsule the logic in the property self (volatile and lock). Is my understanding of the two's correct or have I make any mistakes? Below are my examples: public class ThreadSafeClass { // 1. Volatile Example: private volatile int _processState_1; public int ProcessState_1 { get { return _processState_1; } set

ASynchTask sleep in doinbackground locking the UI thread

我的未来我决定 提交于 2019-12-25 01:45:56
问题 EDIT: SOLVED. Sorry guys, it occurred to me that while my loading of my data was occurring in a background thread, the callback that parsed the data was not. The parsing of the data took a very long time, and that was what was locking my thread. EDIT: It has come to my attention that my overarching problem (the ProgressDialog no longer spinning) may be caused by a problem with my use of a ProgressDialog rather than the UI thread being blocked. If that is the case, how do I fix that? EDIT: to

Hibernate StaleObjectStateException Issue Calling Merge

风格不统一 提交于 2019-12-25 00:25:34
问题 I'm trying to test optimistic locking using JPA's @Version annotation that I've added to my entity object: @Version @Setter(AccessLevel.NONE) @Column(name = "VERSION") private long version; When I run 2 servers concurrently, I receive a StaleObjectStateException : Exception message is : Object of class [com.myPackage.WorkQueue] with identifier [9074]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or

MYSQL slow performance because of Locking

风格不统一 提交于 2019-12-25 00:05:50
问题 I have Mysql5.5 on windows system. Since past 1 month it is running slow. Here is the query which are running the most: begin update roomlogs set roomlogs.exitTime = ptime,roomlogs.`status` = 1 where roomlogs.netId = pnetid and roomlogs.`status` = 0 and roomlogs.enterTime>=DATE(ptime) and roomlogs.enterTime<DATE(ptime) + interval 1 day; INSERT into roomlogs (roomlogs.roomId, roomlogs.netId, roomlogs.enterTime, roomlogs.exitTime, roomlogs.hidden, roomlogs.checkinId) value (pRoomId, pnetid

SELECT… FOR UPDATE selecting old data after a commit

被刻印的时光 ゝ 提交于 2019-12-24 18:18:41
问题 Good day, This is an update to my old post at SQL Simultaneous transactions ignore each other's locks??? DEADLOCK [InnoDB, Python], as I realized later that the issue had nothing to do with what I thought the problem was. I'm trying to create the MySQL equivilent to a T-SQL based script for a client. I have two identical scripts, Alice and Barry running concurrently. Their goal is to SELECT * FROM job WHERE status = 0 LIMIT 1 FOR UPDATE UPDATE job SET status = 1 where jobIDs match, do some

How to lock a xml file usinf flock

痴心易碎 提交于 2019-12-24 17:56:03
问题 After searching through google, it seems everyone uses text file to show an example how to lock a file using flock() then i tried <?php $dom = new DOMDocument("1.0"); $fp = $dom->load('bt.xml'); //$fp = fopen("bt.xml", "w"); if (flock($fp, LOCK_EX | LOCK_NB)) { echo "Got lock!\n"; sleep(10); flock($fp, LOCK_UN); } else { print "Could not get lock!\n"; }?> but it gives an error Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/html/testphp/lock1.php on line 6 Could