Questions tagged [locking]

Locking allows different types of resources to be used exclusively by one process at a time.

For more information see Locks in Java

8782 questions
4
votes
3 answers

Why does MySQL explicit predicate locking disallow INSERT statements outside of the predicate lock

Assuming we have the following database tables: create table department ( id bigint not null, budget bigint not null, name varchar(255), primary key (id) ) ENGINE=InnoDB create table employee ( id bigint not null, name…
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
4
votes
1 answer

Best practice to lock data objects

I wrote an application which handles large text files. Internally a text file is stored as a DataObject which contains several data like the rows of the file, the file path and so on. I can modify these files (the data object respectively) with the…
MrToast
  • 1,159
  • 13
  • 41
4
votes
3 answers

static lock_guard with static mutex too?

So I've some thread-unsafe function call which I need to make thread safe so I'm trying to use a std::mutex and a std::lock_guard. Currently code looks like this - int myFunc(int value){ static std::mutex m; std::lock_guard lock(m); auto…
hg_git
  • 2,884
  • 6
  • 24
  • 43
4
votes
1 answer

Python: Context manager 'lock' doesn't implement __enter__ and __exit__

My code contains what seems to be common practise, using: import threading mylock = threading.Lock() def myfunction(): with mylock: do_something() But my PEP8 pylinter is squawking about: Context manager 'lock' doesn't implement…
jhaagsma
  • 2,414
  • 2
  • 24
  • 26
4
votes
1 answer

How to update random 4 rows in a table using row level locking with Postgres?

We are planning to use a simple flat table without references as a transactional data store in Postgres. The table is constantly being updated from different threads. We need to select maximum 4 minimum 1 row from the table, lock it, do an update on…
Istvan
  • 7,500
  • 9
  • 59
  • 109
4
votes
1 answer

When is the lock released if I return from the synchronized block?

I am confused over the point at which the lock is released if I have a return statement from the synchronized block; to find that out I have added try-finally block and added a sysout inside finally block printing 'lock released' but I can clearly…
Venkatesh Laguduva
  • 13,448
  • 6
  • 33
  • 45
4
votes
1 answer

Does SELECT query lock a table or a page in SQL Server?

We have just upgraded our production sql instance from 2012 to 2016 Standard Edition. As we have been working hard to find deadlocks in case it exists, i have just faced one and didnt quite understand what is exactly happening. The reason i did not…
Yasin Bilir
  • 194
  • 3
  • 17
4
votes
2 answers

TFS claiming files are locked even though they are not - Orphaned Locks

I'm trying to perform a baseless merge between two branches using tf.exe. When I run the command, it fails and tells me that there 15-20 files that are locked by another user. I've looked at the other user's pending changes and he only has three…
ryan.rousseau
  • 1,595
  • 1
  • 11
  • 22
4
votes
1 answer

Java lock and unlock in different methods. How to try/finally?

I'm trying to figure out what is the best way to use the try/finally with locks. When I have lock() and unlock() in the same place, I just use the try/finally block as the JavaDoc also suggests: lock.lock(); try{ // do something } finally { …
smellyarmpits
  • 1,080
  • 3
  • 13
  • 32
4
votes
1 answer

Python: Building a Reentrant Semaphore (combining RLock and Semaphore)

How would you go about combining threading.RLock with threading.Semaphore? Or does such a structure already exist? In Python, there is a primitive for a Reentrant lock, threading.RLock(N), which allows the same thread to acquire a lock multiple…
speedplane
  • 15,673
  • 16
  • 86
  • 138
4
votes
4 answers

Making a password lock for an app?

I'm wanting to make a password unlock screen for my app, and I'm not sure how I'd go about it. I'm wanting it to look like the Apple-designed version of it, which is the passcode lock setting screen. How might I go about doing something like this,…
sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
4
votes
3 answers

When implementing a thread safe queue or list, is it required to lock before returning Count?

When implementing a thread safe list or queue; does it require to lock on the List.Count property before returning the Count i.e: //... public int Count { lock (_syncObject) { return _list.Count; } } //... Is it necessary to do…
Jalal Said
  • 15,906
  • 7
  • 45
  • 68
4
votes
3 answers

locking during nservicebus handler

I have a scenario wherein a nservicebus message handler I need to prevent multiple messages for the same saga from being executed at the same time. The handler for arguments sake does something like this (way oversimplified in this…
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108
4
votes
1 answer

Should I use cflock or not?

I would like to know if locking my table is necessary in this situation (I'm using Coldfusion and MySQL): I have a table called wishlists(memberId, gameId, rank, updateAt) where members store games in a personal list. wishlists has a man-to-many…
Mohamad
  • 34,731
  • 32
  • 140
  • 219
4
votes
1 answer

ZipFile.getEntry causing java aplication to hang

I have this application that is hanging with no apparent reason. I performed a thread dump in order to check what is being done by the application while on that state and found out almost all my HTTP threads were stuck on ZipFile.getEntry as…
Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106