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
4 answers

MySQL InnoDB lock question

I have a question about MySQL InnoDB. For example: I have the following table created: mysql>CREATE TABLE IF NOT EXISTS `SeqNum` ( `id` varchar(10) NOT NULL, `seq_num` BIGINT(30) default 0, PRIMARY KEY(`id`) ) ENGINE=InnoDB…
WilliamLou
  • 1,914
  • 6
  • 27
  • 38
4
votes
3 answers

Multi-threading problem when checking the list Count property

I have List newJobs. Some threads add items to that list and other thread removes items from it, if it's not empty. I have ManualResetEvent newJobEvent which is set when items are added to the list, and reset when items are removed from it: Adding…
mayap
  • 569
  • 5
  • 19
4
votes
4 answers

How can I ensure only one copy of a Perl script is running at a time?

I need to ensure that only one copy of my Perl script is running at a time. According to the suggestions here I wrote a sub to do the check: sub check_instances { open my $fh, '<', $0 or die $!; unless (flock($fh, LOCK_EX|LOCK_NB)) { …
planetp
  • 14,248
  • 20
  • 86
  • 160
4
votes
1 answer

Lock a whole target in a Makefile

I have a Makefile with a target that executes multiple system-wide operations (e.g. installing packages), so I want to lock the target in a way that other make processes will wait on that target, thus preventing parallel execution. I tried using…
framos
  • 43
  • 6
4
votes
1 answer

Is there a better way to wait for two threads to complete their tasks than using the CountDownLatch?

My requirement is to wait for two threads to complete execution before kickstarting a dependent job. In order to do this, I am able to create a CountDownLatch and a Waiter Thread which will wait for the CountDownLatch to become zero. One constraint…
The Roy
  • 2,178
  • 1
  • 17
  • 33
4
votes
1 answer

portalocker does not seem to lock

I have a sort of checkpoint file which I wish to modify sometimes by various python programs. I load the file, try to lock it using portalocker, change it, than unlock and close it. However, portalocker does not work in the simplest case. I created…
Berta Dénes
  • 93
  • 3
  • 11
4
votes
1 answer

Howto enable lock usage in MongoDB 3.2.8 - Failed: server does not support reporting lock information

From MongoDB docs To report the use of per-database locks, use --locks Changed in version 3.0.0: When called against a mongod that does not report lock usage, --locks will return a Failed: Server does not support reporting locking information…
Sybil
  • 2,503
  • 3
  • 25
  • 36
4
votes
5 answers

Any downsides to locking a collection vs. a syncRoot?

I'm wondering if there are any downsides to locking over a collection such as a List, HashSet, or a Dictionary rather than a simple object. Note: in the following examples, that is the only place where the locks occur, it's not…
ckknight
  • 5,953
  • 4
  • 26
  • 23
4
votes
2 answers

Why is fs.createReadStream ... pipe(res) locking the read file?

I'm using express to stream audio & video files according to this answer. Relevant code looks like this: function streamMedia(filePath, req, res) { // code here to determine which bytes to send, compute response headers, etc. …
danludwig
  • 46,965
  • 25
  • 159
  • 237
4
votes
4 answers

Is Map of Locks a safe approach for concurrent operations

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…
R H
  • 387
  • 3
  • 13
4
votes
3 answers

Prevent simultaneous transactions in a web application

We have a web application (it is a game) with lots of various forms and elements which act as buttons and trigger some actions on server. The problem is that users can sometimes confuse our application if he clicks on buttons too fast or opens the…
JustAMartin
  • 13,165
  • 18
  • 99
  • 183
4
votes
2 answers

fopen file locking in PHP (reader/writer type of situation)

I have a scenario where one PHP process is writing a file about 3 times a second, and then several PHP processes are reading this file. This file is esentially a cache. Our website has a very insistent polling, for data that changes constantly, and…
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
4
votes
2 answers

acquire multiple thread sync locks simultaneously

Let's assume following code, which is used in similar way in my application: //------------------------------------- void UseAllResources () { bool bSuccess1 = false; bool bSuccess2 = false; try { bSuccess1 = Monitor::TryEnter…
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
4
votes
1 answer

Locking without hardware support

I think most locking techniques assumes or makes use of hardware support for atomic transactions. I remember reading about some locking/synchronization algorithms which doesn't need such support, but can't really recall them (token-based or…
Jeenu
  • 2,109
  • 2
  • 20
  • 27
4
votes
1 answer

How do I use `lock_hash_recurse` in Perl?

In continue to the discussion here, I'm havind some trouble with lock_hash_recurse as illustrated below: #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Hash::Util qw (lock_keys); my $hashref = {A=>1, B=>{CC=>22,…
David B
  • 29,258
  • 50
  • 133
  • 186