Locking allows different types of resources to be locked by a transaction.
32
votes
5answers
7k views
Thread-Safe and Lock-Free - Queue Implementation
I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently.
Would you ...
14
votes
2answers
1k views
Lock-free cache oblivious n-body algorithm
I'm currently looking at, from a rather high level, the parallelization of the gravity calculation in an N-body simulation for approximating a solution to the N-body problem.
The simple form of the ...
12
votes
6answers
15k views
A custom thread-pool/queue class
I wanted a class which executes any number of tasks but only a certain amount at the same time (e.g. to download various internet content and keep the overall download speed at a good level). The ...
12
votes
4answers
1k views
Force locking for thread-safety
After reading Herb Sutter's Associate Mutexes with Data to Prevent Races, I found that my solution was superior in several aspects, least important first:
The code is cleaner, without macros
No ...
11
votes
2answers
364 views
Is this use of a resource based on session ids thread safe?
Let me first describe the expected behavior of the code below:
There will be one static SessionManager accessed by many threads.
Multiple calls to ...
10
votes
3answers
3k views
Waiting for a lock to release with Thread.Sleep()?
There's a follow-up: Waiting for a lock to release with ManualResetEvent and Quartz.
I've written a simple Lock-Mechanism which is saving the states of the locks in a database. Now I need to wait ...
10
votes
2answers
245 views
RAII Pattern for Downgradable ReadWriteLock
The example for downgrading ReentrantReadWriteLock in the Java documentation seems really unsafe when handling exceptions. I tried to write a simple class to simplify it. Do you see any cases where it ...
7
votes
6answers
764 views
Reading a line of text from a socket
I tend to write code, with very few comments, and few line breaks. I'm currently just a student at a University. I've had professors tell me one way or another to comment, but I have a hard time with ...
7
votes
2answers
2k views
A simple semaphore in Java
It is a simple semaphore in Java. Although it passes all their tests with flying colors, I'm still not sure it's correct.
For example, the last thing I wasn't sure about was ...
7
votes
2answers
292 views
Spinlock for C++ kernel (with x86 ASM)
This is some prototype code for a spin-lock for my toy operating system. Bear in mind this means there are no standard library routines to fall back on. It's also for C++11 compilation and will only ...
7
votes
1answer
528 views
7
votes
3answers
11k views
Dining philosophers problem with mutexes
I know this dining philosophers problem has been researched a lot and there are resources everywhere. But I wrote simple code to solve this problem with C and then turned to the Internet to see if ...
7
votes
2answers
364 views
Synced/Atomic access
Forward
I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below.
If this is similar to other implementations, I would love ...
7
votes
1answer
230 views
Simple, encapsulated C++ logger that can deal with fork/exec situations
Motivation: for whatever reason, some of the available 3rd party logging libraries don't really deal with programs that get fork'ed/exectuted well. For instance, ...
7
votes
1answer
3k views
“Fast” Read/Write Lock
I need a Read-Write lock that is fast and generally portable on Windows machines (including XP, otherwise I'd just use the SRWLock that was introduced with Vista). I've written this custom ...
7
votes
1answer
656 views
Portable C++ boost::interprocess::mutex
I was looking for long time around to have a portable robust solution for multiprocessing synchronization. Who touche this things know that good solution are boost::iterprocess named sync objects.
...
7
votes
0answers
242 views
Concurrency limit map in Go
Please someone who knows locks, mutexes, and Go, review the following code.
Task: per host concurrency limits for web crawler (map[string]Semaphore).
I considered chan struct{} (chan bool) approach, ...
6
votes
1answer
2k views
Waiting for a lock to release with ManualResetEvent and Quartz
Follow-up to: Waiting for a lock to release with Thread.Sleep()?
I've found the time I tried to rewrite my WaitForLock-Method to utilize the Quartz.NET ...
5
votes
3answers
130 views
Feedback on thread safety of the classes
I have following classes. Are they properly guarded for thread safety? Do you see any issues with any of the classes?
...
5
votes
2answers
197 views
Generic Object Pool in C#
I have a limit of 100 sessions (each session held in an object). Many threads will be requesting sessions, and it is very possible that all 100 sessions could be in use at any time.
I'm a Junior ...
5
votes
1answer
112 views
Is my spin-lock implementation correct?
I'm working on a project where a spinlock is more appropriate than a mutex, and after few tries I came up with:
...
5
votes
1answer
174 views
Using CountDownLatch for blocking the reads if writes are happening
I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three maps.
Requirements:
Reads block until all three maps have been set for the first ...
5
votes
1answer
326 views
Operations on files and their locks - code too bulky?
A couple of hours ago I asked a question on Stackoverflow to find out if there is a good way to delete files in a folder only if all files are indeed deletable and I got some good answers that led me ...
5
votes
1answer
36 views
Simple file locking wrapper command in C
A simple command that wraps another command, locking a file first. It is similar to flock, just simpler.
...
5
votes
1answer
2k views
C++ critical section with timeout
NOTE: My implementation is based on codeproject article by Vladislav Gelfer.
Based on valdok's codes, I rewrote the critical section class. The difference is that my implementation integrated ...
5
votes
4answers
1k views
Associating a lock/mutex with the data it protects
I've recently come across some areas of code in our solution that have a few thread-safety problems. Thread-safety is a minefield at best so I thought I'd have an attempt at writing a few little ...
5
votes
0answers
123 views
Deadlock watchdog in a server to defend against poorly written extensions
In the Red5 server we have no control over what implementers do with their applications. As such, we have attempted to implement code that would prevent them from causing bad things to happen.
This ...
4
votes
3answers
484 views
Using goto to wait on the result of a database query to change
This is a small personal project where most non-sensitive data is distributed to some globally hosted CDN servers, which store the JSON. Now one problem we've seen during testing is a few deadlocks ...
4
votes
2answers
185 views
Getting a decryptor object
I need to lock on my AesManaged instance _Aes to call CreateDecryptor() however the CreateDecryptor() method is not thread safe and this function could be called by ...
4
votes
1answer
2k views
Locking during cache population
Here I want to lock when populating a particular cache object, without blocking other calls to the same method requesting Foos for other ...
4
votes
2answers
5k views
Did I need to use lock to ensure that Queue.Dequeue is Thread Safe in this case on .NET 2.0?
Is this ok? I am using C# and .NET 2.0
I have this Queue declared in my class :
...
4
votes
1answer
603 views
Async distributed locking with StackExchange.Redis [closed]
I have been trying to write an analogy to this approach to distributed locking with two differences:
making it asynchronous
making it work with StackExchange.Redis rather than AppFabric Cache.
My ...
4
votes
1answer
271 views
Is this the best message delay algorithm?
In my application I am attempting to queue outgoing messages by the following rules
By default they should be sent no less than messageDelay apart
Some messages ...
4
votes
1answer
208 views
Improving handling of data structure used in parallel
I have a class extending the Dictionary class. This class is used for storing some information (modeled in CustomClass) and accessing it through an integer ID.
To ...
4
votes
2answers
12k views
Using Timer with Backgroundworker to ensure the doWork method is called
I have a windows forms application in which a backgroundworker is called again and again.
I need to avoid concurrent access of the code in dowork method for the backgroundWorker; but also need to ...
4
votes
1answer
146 views
How to avoid reads before initialization is complete and return updated set of maps value?
This is a follow on to: How to prevent reads before initialization is complete?
I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three ...
4
votes
1answer
602 views
Single word CAS tagged pointer for algorithms susceptible to the ABA problem
I've been looking for a solution to the ABA problem for a lock-free stack. Searching the Web revealed patented and complicated hazard pointers and tagged pointers using double compare-and-swap (DCAS, ...
4
votes
1answer
2k views
Transactions and locking in Rails 3
I am new to Rails and have a system that needs to process transactions.
A user can enter a transaction to which one or more users are tied. These users owe some amount of money to the person making ...
4
votes
2answers
101 views
Generic object pool class using Spinlock/Monitor
I've written the following object pool class, and because this is my first encounter with synchronization primitives, I need reinsurance from an expert that this code is safe. I've tested it myself ...
3
votes
4answers
2k views
Java Non Reentrant Lock Implementation
I have implemented a Non Reentrant Lock. I want to know if this has any mistakes, race conditions etc. I am aware of the fact that existing libraries have to be used (instead of writing our own), but ...
3
votes
2answers
560 views
Prevent re-entrant function call in C++
The purpose of this is to prevent a re-entrant function call in a single thread, e.g. prevent the situation where func() calls ...
3
votes
4answers
332 views
Configurable synchronization approach in Java
I am interested in the community opinion about the following approach for the synchronization.
Generally it is based on the idea to have a configurable way to apply locking on some logic parts.
Any ...
3
votes
1answer
33 views
Good approach to raise an exception
I have class House and module Lockable. Locking and unlocking House should reflect the real ...
3
votes
2answers
95 views
Locking a remote file
I am using Java to modify remote files in different machines by ssh. At the same time, only one thread is allowed to modify the file in one machine.
I implement the logic like this:
...
3
votes
1answer
658 views
Mutex implementation for a uniprocessor bare metal embedded OS
I wrote this recently for one of my projects. Are there any error you can spot or a feature which could be implemented without eating up resources or some optimisations? Also, this isn't meant for ...
3
votes
1answer
118 views
Moonshot & `Thread.Abort` - dealing with the fallout
Recently, I encountered an anomaly in the manner by which a worker thread was terminated. It prompted me to do some searching and I realized that I was constructing thread code in a haphazard manner. ...
3
votes
1answer
166 views
Social Share count
I am creating a social sharing counter plugin for my WordPress blog. I want to fetch the counts of number of likes, shares, Facebook comments (I am using Facebook comment box), twitter tweet counts ...
3
votes
1answer
1k views
Resource Pool implementation with ReentrantLock and Condition
The Resource Pool is similar to the implementation of a semaphore. It takes the class type of the resource and number of resource pools associated with it as the constructor parameters. There is a ...
2
votes
4answers
7k views
Designing a better logger class
Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or ...
2
votes
1answer
969 views
Monitoring progress in Parallel.ForEach every minute
I'm using Parallel.ForEach to download 500K URLs and I want to monitor the number of URLs that have been successfully downloaded each minute.
...