Locking allows different types of resources to be locked by a transaction.

learn more… | top users | synonyms (1)

3
votes
0answers
19 views

Async distributed locking with StackExchange.Redis

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 ...
1
vote
1answer
57 views

Thread lock algorithm

I am trying to make a thread lock for a method so that only one thread can run it at a time. Although this is a well known issue and in C# there is the lock keyword to do it. I was trying to do it on ...
4
votes
1answer
24 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. ...
4
votes
3answers
401 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
0answers
95 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 and as such we have attempted to implement code that would prevent them from causing bad things to happen. ...
5
votes
2answers
99 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 ...
7
votes
6answers
718 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
0answers
115 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, ...
3
votes
2answers
65 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: ...
1
vote
1answer
225 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. ...
10
votes
2answers
177 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 ...
5
votes
1answer
91 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: ...
3
votes
1answer
30 views

Good approach to raise an exception

I have class House and module Lockable. Locking and unlocking House should reflect the real ...
1
vote
2answers
89 views

SynchronizedArrayList implemented using reader writer synchronization

I am trying to understand the workings of reader writer locks. For the sake of learning, I implemented reader writer synchronization by my own. I implemented ...
7
votes
1answer
398 views

Portable C++ boost::iterprocess::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. ...
1
vote
0answers
110 views

Lock a process in PHP

We had a situation where it was necessary that a script only be running in one process at a time. The solution was to make a "LockByProcess" class that checks a database for an existing process, and ...
2
votes
1answer
185 views

Mutualising multi-threaded calls to EJB from Servlet

I have a Servlet that makes an EJB call to a backing server which takes about a second to return some data that changes reasonably regularly. I can't cache the data on the servlet-side, so I have ...
7
votes
2answers
1k 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 ...
3
votes
2answers
467 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 ...
1
vote
0answers
72 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
130 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 ...
2
votes
1answer
117 views

Testing Promises vs Lock performance

I'm not sure if my lock usage is correct and safe. I wanted to know what will be best approach to deal with situation when one thread have to wait for being initialized by another so I written this ...
5
votes
1answer
131 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 ...
4
votes
1answer
125 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 ...
1
vote
0answers
78 views

Reliability of flock mutex (LOCK_EX|LOCK_NB)

I would like to test reliability of system flock in a multi-threaded and concurrent environment as some suggest that they are not reliable (in comments). Thus I ...
11
votes
2answers
259 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 ...
5
votes
3answers
128 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
1answer
133 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 ...
2
votes
0answers
241 views

Python app-level document/record locking (eg. for MongoDB)

Introduction MongoDB does not provide means to lock a document (like SELECT FOR UPDATE in RDBMS). There is recommended approach to Isolate Sequence of Operations, which is sometimes called ...
1
vote
1answer
217 views

RAII-Style Lockable Objects

TL;DR: Without the phrases "use Boost" and "use C++11", does the posted code for RAII-style locking of a resource look correct and safe, or is there something I've missed. Long Version: I am working ...
2
votes
2answers
270 views

File locking between server threads

I have written the below code where the server is getting requests from clients on a socket and creating a thread per client. Each client thread is then writing to a file which is common to all the ...
4
votes
1answer
1k 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 ...
1
vote
1answer
369 views

Loading data async with queue. Proper write only locking and scheduling

I have to store and return data on multitasking requests. If data is missing, I schedule loading and return null. I'm using some nubie scheduling by saving current jobs in a list. Also I need data ...
0
votes
2answers
82 views

Is this a good way of handling item reservations?

I have a site were we sell unique items. When a user clicks to buy an item we have to reserve it. This prevents other buyers from purchasing the item while the first buyer is checking out. When a ...
4
votes
1answer
215 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 ...
1
vote
4answers
507 views

Multi-threaded utility that logs some audit trails

I'm trying to write a multi-threaded utility that logs some audit trails to the DB every 30 minutes, or whenever my storage data structure (a list in this case) exceeds a certain limit. The code ...
7
votes
3answers
8k 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 ...
1
vote
2answers
4k views

Static class ThreadPool implementation

The following code is a self-implementation of the static class ThreadPool in C#, only the QueueUserWorkItem (the simpler ...
2
votes
4answers
5k 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 ...
1
vote
3answers
82 views

How to correctly get a IDisposeable when you need to lock the factory?

If I need to create a IDisposeable object from a factory, but if the factory object is not thread safe and requires me to lock on it is this the correct pattern to use? ...
4
votes
2answers
151 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 ...
7
votes
2answers
341 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 ...
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 ...
1
vote
2answers
2k views

Multithreading concepts with Producer Consumer

I just wanted to confirm if this example I created would qualify as a good example of a multithreaded producer consumer. I would like any review changes on improving this example. I found that static ...
3
votes
4answers
1k 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 ...
6
votes
0answers
205 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, ...
4
votes
1answer
198 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 ...
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 ...
2
votes
1answer
528 views

Mutex implementation for uniprocessor bare metal embedded OS

I wrote this recently for one of my projects, any error you guys can spot or a feature which could be implemented without eating up resources or some optimisations ? Oh and it isn't meant for Multi ...
3
votes
4answers
290 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 ...