locking

Acquiring multiple locks atomically in java

空扰寡人 提交于 2019-12-06 05:06:31
问题 I have the following code: Note: I simplified the code as much as possible for readability. If I forgot any critical pieces let me know. public class User(){ private Relations relations; public User(){ relations = new Relations(this); } public getRelations(){ return relations; } } public class Relations(){ private User user; public Relations(User user){ this.user = user; } public synchronized void setRelation(User user2){ Relations relations2 = user2.getRelations(); synchronized(relations2){

Is Map of Locks a safe approach for concurrent operations

此生再无相见时 提交于 2019-12-06 04:49:35
问题 The requirement is only single thread must be allowed to perform user management (create/update/import) operations but multiple threads are not allowed to perform user operations simultaneously for the same user. For example, When Thread A is creating User A then concurrently Thread B must not be allowed to import User A Or Creating User A but Thread B is allowed to import User B. Is the below code thread safe for these requirements? public class UserManagement { ConcurrentHashMap<Integer,

What's the corresponding prefix in arm assembly for “lock” in x86?

你说的曾经没有我的故事 提交于 2019-12-06 03:31:01
I have a x86 assembly code: unsigned int oldval; __asm__ __volatile__ ( "movl $1, %0 \n" "lock xaddl %0, (%1) \n" : "=a" (oldval) : "b" (n))l; return oldval; and I want to translate it into arm assembly. Is there any prefix in arm assembly that does the same thing as "lock" here? I don't know ARM, but from glossing over the manual, the following should approximate your atomic exchange-and-add: foo: LDREX R1, [R0] ; R0 is "n", load linked ADD R2, R1, 1 ; R2 = R1 + 1 STREX R3, R2, [R0] ; store conditionally, R3 = 0 if and only if success CBNZ R3, foo ; on failure, try again ;; now return R1 to

How does the NSCondition work?

自作多情 提交于 2019-12-06 03:30:48
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 calls [cocoaCondition signal] , the thread1 will resume running. I've test the code and it works just

How do I check if an object is being @synchronized

不问归期 提交于 2019-12-06 03:07:08
问题 Sometimes I wrote the following code to synchronized a routine: @synchronized(objToBeSync){ .... } When two threads try to access the sync block at the same time, one will block the others, until the one exits the sync block. However, sometimes I don't want one blocks the other, but the others check if the object is being synchronized, and then do some other thing so I have to do sth like this: @synchronized(objToBeSync){ _isBeingSync = YES; ... _isBeingSync = NO; } _isBeingSync is an

Lock file in Xcode 4

六月ゝ 毕业季﹏ 提交于 2019-12-06 02:46:29
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? 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 clicking the file in the Project Navigator and selecting Show In Finder. Using Get Info (Cmd-I) will allow

Can Oracle's default object lock timeout be changed?

为君一笑 提交于 2019-12-06 02:16:33
问题 > ALTER PACKAGE blah COMPILE; (wait about 10 minutes) > ORA-04021: timeout occurred while waiting to lock object I understand why I get the timeout error (the package is in use). Does anyone know if there's a way to change the default 10 minute wait interval? Can this be configured at a database / session / statement level? Thanks 回答1: there is a DDL_LOCK_TIMEOUT parameter since 11gR1 : DDL_LOCK_TIMEOUT specifies a time limit for how long DDL statements will wait in a DML lock queue. The

Obtain data synchronously from WebWorker?

假装没事ソ 提交于 2019-12-06 02:05:20
问题 While I understand that JavaScript is inherently single-threaded and generally frowns upon such things, I am wondering if there is any way to get a WebWorker to wait until some data is made available from the main thread without destroying the call stack of the WebWorker. As this is for a fun project, I can use new technologies and things that won't reliably run on older browsers, and I don't mind esoteric hacks as long as they work. Some other solutions that I have thought about:

Virus scanners locking and deleting temporary files - best way to cope with them?

吃可爱长大的小学妹 提交于 2019-12-06 02:01:00
问题 My application deals with e-mails coming from different sources, e.g. Outlook and IMAP mailboxes. Before parsing them, I write them to the temporary directory (keeping them in memory is not an option). While parsing, I might be writing attachments to the temp directory (for example, if they are too large to keep in memory or for full-text extraction). But in the wild, two things happen that seemed very strange in the first place but could all be traced back to virus scanner behaviour: I'm

HttpURLConnection getting locked

北城余情 提交于 2019-12-06 01:44:48
问题 I have a thread running under tomcat which creates a HttpUrlConnection and reads it through BufferedInputStream. After fetching data for some urls, it stalls. I got the jstack of the process which says HttpUrlConnection is locked and BufferedInputStream is also locked. "http-8080-1" daemon prio=10 tid=0x08683400 nid=0x79c9 runnable [0x8f618000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java