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
1 answer

Locks around memory manipulation via inline assembly

I am new to the low level stuff so I am completely oblivious of what kind of problems you might face down there and I am not even sure if I understand the term "atomic" right. Right now I am trying to make simple atomic locks around memory…
user1235831
  • 111
  • 1
  • 8
4
votes
4 answers

My C# app is locking a file, how I can find where it does it?

I'm writing code that check files path calculate hash (SHA1) and copy them. I made sure that I do not lock them like for example using public static string SHA1(string filePath) { var fs = new FileStream(filePath, FileMode.Open,…
Data-Base
  • 8,418
  • 36
  • 74
  • 98
4
votes
2 answers

Java 6 JVM Hang

Apologies for the long post, but I wonder if I could get some more eyeballs on this before I submit a bug report to Sun. JVM: 6u11 O/S: Windows XP SP3 Hardware: AMD Athlon 64 X2 4600+ @ 2.41GHz, with 3.25 GB RAM. I believe I have encountered a fault…
Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
4
votes
3 answers

c# multithreading - Is there a need to lock when writing to DB?

I've got a multithreaded C# 2.0 app where each thread writes some results into a SQL server 2000 database table. There is only a straight INSERT command and no other logic. My question is - do I need to put a lock around the methods that writes the…
Misha
  • 75
  • 4
4
votes
3 answers

Coding Style: lock/unlock internal or external?

Another possibly inane style question: How should concurrency be locked? Should the executor or caller be responsible for locking the thread? e.g. in no particular language... Caller::callAnotherThread() { …
Stephen Furlani
  • 6,794
  • 4
  • 31
  • 60
4
votes
1 answer

Java -Check if file is in print Queue / In Use

OK I have a program that: Creates a temporary file based on a users input Prints the File(Optional) Deletes the File (Optional) My problem sits between stages 2&3, I need to wait for the file to finish printing until I can delete it. FYI: the…
Gwilym
  • 775
  • 2
  • 9
  • 19
4
votes
1 answer

Data mismatch when querying with different indexes

I stumbled upon with a very curious case. We have a SQL Server 2012 database and such a table CREATE TABLE [dbo].[ActiveTransactions] ( [Id] [BIGINT] IDENTITY(1,1) NOT NULL, [Amount] [DECIMAL](12, 4) NOT NULL, [TypeId] [SMALLINT] NOT…
Dimitri
  • 2,798
  • 7
  • 39
  • 59
4
votes
4 answers

Should I protect operations on primitive types with mutexes for being thread-safe in C++?

What is the best approach to achieve thread-safety for rather simple operations? Consider a pair of functions: void setVal(int val) { this->_val = val; } int getVal() { return this->_val; } Since even assignments of primitive types…
mip
  • 8,355
  • 6
  • 53
  • 72
4
votes
2 answers

tryLock unreleased resource

The code below has been flagged as a violation by Fortify ("unreleased resource" for the lock) try { if (lock.tryLock(1, TimeUnit.SECONDS)) { try { //do something } finally { lock.unlock(); } } catch…
alampada
  • 2,329
  • 1
  • 23
  • 18
4
votes
1 answer

Hazelcast: how to ensure cluster startup is finished

I have a cluster with 3 nodes (in different machines) and I have a "business logic" that use a distributed lock at startup. Sometimes when there is more latency every node acquires the exclusive lock with success because the cluster isn't already…
Simona R.
  • 558
  • 6
  • 20
4
votes
3 answers

Car Park in Java, decrementing spaces

I'm creating a car park in Java, I have one entrance and one exit. The car park has 20 spaces and and I think I've coded the entrance/exit correctly, I have been asked to use threading. import java.io.*; public class CarPark { private int…
collision934
  • 31
  • 1
  • 9
4
votes
3 answers

Second thread enters lock before first thread releases it

I'm playing with some threading constructs in C#, and ran into something that defies my understanding of how locking works. I have a helper function that accepts an asynchronous task, and uses a TaskCompletionSource member to try and synchronize…
KChaloux
  • 3,918
  • 6
  • 37
  • 52
4
votes
4 answers

spin_lock on non-preemtive linux kernels

I read that on a system with 1 CPU and non preemtive linux kernel (2.6.x) a spin_lock call is equivalent to an empty call, and thus implemented that way. I can't understand that: shouldn't it be equivalent to a sleep on a mutex? Even on…
Emiliano
  • 22,232
  • 11
  • 45
  • 59
4
votes
2 answers

How to lock table between read and write operations

I've a situation where each new record should contain a unique and readable value. This value has a business meaning for the user and will be handled as a natural id (next to primary key) in our database. To give you an idea of the value's…
user2054927
  • 969
  • 1
  • 12
  • 30
4
votes
3 answers

RAII thread safe getter

Most of the times I see in the code some variant of this kind of implementation for a thread safe getter method: class A { public: inline Resource getResource() const { Lock lock(m_mutex); return m_resource; …
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64