mutual-exclusion

Mutual exclusion: is this safe?

Is this pattern for mutual exclusion as safe as I think it is? If so, what do you call it? lock (_lock) { if (_flag) return; else _flag = true; } try { //critical code... } finally { _flag = false; } I want to ensure the critical section, but without the other threads piling up waiting to acquire the lock. Obviously I ...

Why the name "monitor"?

I'm referring to monitors as described here: http://en.wikipedia.org/wiki/Monitor_(synchronization) None of the definitions here seem apropos: http://www.thefreedictionary.com/monitor So why are they called that? == Update == Thank you for the answers, everyone! I guess I was confused because I don't think of monitors usually as a...

Mutex Stored Procedure

Hi All, I want to create some distributed mutual exclusion using a database table. It would be nice to have the following interface on a stored procedure: Wait(uniqueidentifier) I was originally thinking of implementing this by having a table of unique identifiers. A call to the procedure would wait until the unique identifier does no...

Mutual exclusion and C Sockets

I am maintaining an existing system where previous developers on each operation is performed on the socket, to which multiple threads are required to read and write to, the previous developers have performed the io operations under the control and a mutex. is there a requirement to mutually exclude C socket IO operations? Or since socke...

Difference Between Monitor & Lock?

What's the difference between a monitor and a lock? If a lock is simply an implementation of mutual exclusion, then is a monitor simply a way of making use of the waiting time inbetween method executions? A good explanation would be really helpful thanks.... regards ...

What's the best linux kernel locking mechanism for a specific scenario

Hi, I need to solve a locking problem for this scenario: A multi CPU system. All of the CPU's use a common (software) resource. Read only access to the resource is very common. (Processing of incoming network packets) Write access is a lot less frequent. (Pretty much configuration changes only). Currently I use the read_lock_bh, wri...

Read/write synchronization

I have a data structure whose operations can be categorized as read operations (e.g. lookup) and write operations (e.g. insertion, removal). These operations should be synchronized so that: Read operations can't execute while a write operation is executing (unless on the same thread), however read operations can be executed concurrentl...

Mutual-exclusion using TestAndSet() instruction

The book Operating System Principles by Silberschatz, Galvin and Gagne contains the following definition for the TestAndSet() instruction in the chapter on synchronization: boolean TestAndSet(boolean *target) { boolean rv = *target; *target = TRUE; return rv; } An implementation of mutual-exclusion using the above instruct...

Is my spin lock implementation correct and optimal?

I'm using a spin lock to protect a very small critical section. Contention happens very rarely so a spin lock is more appropriate than a regular mutex. My current code is as follows, and assumes x86 and GCC: volatile int exclusion = 0; void lock() { while (__sync_lock_test_and_set(&exclusion, 1)) { // Do nothing. This GCC ...

Condition Sync and Mutual exclusion Java

Hi, I understand that Java associates a lock with every shared object to ensure mutual exclusion and condition sync. I am told to model a Java recursive lock as a FSP process.. but I'm stuck and below is the question and what I've written so far. HELP IS GREATLY GREATLY APPRECIATED. QNS: Given the following declarations: const N = 3 ra...

how to model mutually exclusive attributes in UML?

I'm working up an analysis model in UML, and I'm a bit stuck when trying to represent a constraint on a couple of attributes in a class diagram. In the following class: +-----------+ | SomeClass | +-----------+ | isFoo | | isBar | | isBaz | | isQuux | +-----------+ all the listed attributes are Boolean types, and the f...

SELECT limiting to only results based on a CSV list from a separate table

So I have a list of CSVs in one table. (EG: 1,3,19 ) I want to search out all of the usernames from the other table where the ids match any of those. I feel like I should be able to do something like: <? $query = "SELECT player_ids FROM cast_list WHERE game='".$gameid."' "; $result = mysql_query($query) or die(mysql_error()); $player...

What is equivalent of the C# lock statement in PHP?

For concurrency and ensuring the integrity of the data, how would you obtain a mutual-exclusion lock for a given object? Would you need to use locking within the database, or a file, or does PHP support something like this? ...

C#: How to prevent two instances of an application from doing the same thing at the same time?

If you have two threads within an application, and you don't want them to run a certain piece of code simultaneously, you can just put a lock around the piece of code, like this: lock (someObject) { // ... some code } But how do you do the same thing across separate processes? I thought this is what you use a "global mutex" for, s...

How to prevent multiple access to a webpage?

Say I have a web service where I want to serve the content only once. After it is served any other access to that url should generate an error message. How would I go about doing something like this? What if 2 clients access the url in the same exact moment? ...

PHP mutual exclusion (mutex)

Read some texts about locking in PHP. They all, mainly, direct to http://php.net/manual/en/function.flock.php . This page talks about opening a file on the hard-disk!! Is it really so? I mean, this makes locking really expensive - it means each time I want to lock I'll have to access the hard-disk )= Can anymore comfort me with a deli...

Mutually exclusive regular expressions

If I have a list of regular expressions, is there an easy way to determine that no two of them will both return a match for the same string? That is, the list is valid if and only if for all strings a maximum of one item in the list will match the entire string. It seems like this will be very hard (maybe impossible?) to prove definiti...

MS-Access Junction Table Inserts/Deletions Between Two Mutually Exclusive Lists (2 Listboxes)

With this kind of design, I would like to create a functionality with which to add and delete records from the junction table. The case is from when editing an employee and selecting what exams they can take. In the left list box would be the exams that they aren't eligible for (yet, anyway) and the exams that they are eligible for on ...

Mutual Exclusion Without Touching Both Processes

I have a unique problem. There are two processes (P0 and P1) trying to access one file. P0 is writing information to the file and P1 is reading the information. There is a race condition occurring between the two in which P1 is reading before P0 is finished writing. I have considered using Locks, Semaphores, etc. However, P1 exists in a ...

File open problem with many process in C

Hi Everyone , Iam working in c++ .i have an problem while run an application ,which have my dll within it ,My dll code is suitable to application (needed process).i wrote a log file (xml file) throughout application using fopen within all function(dll source) ,here i receive exception like "cannot access the file ,due to using by anot...