semaphore

Semaphores values

I have a question regarding using Semaphores HANDLE WINAPI CreateSemaphore(...); Is there anyway I can get the current value of the semaphore? ...

Synchronizing Asynchronous request handlers in Silverlight environment

For our senior design project my group is making a Silverlight application that utilizes graph theory concepts and stores the data in a database on the back end. We have a situation where we add a link between two nodes in the graph and upon doing so we run analysis to re-categorize our clusters of nodes. The problem is that this re-cate...

Semaphores in unmanaged code

I've been using the Semaphore class to create semaphores. However, the examples use managed code (requires /clr), and I need to use unmanaged code because it seems FreeType doesn't like working with managed code. How can I create two simple threads which use a semaphore in unmanaged code? ...

Semaphore race condition?

I have created a "Manager" class that contains a limited set of resources. The resources are stored in the "Manager" as a Queue. I initialize the Queue and a Semaphore to the same size, using the semaphore to block a thread if there are no resources available. I have multiple threads calling into this class to request a resource. Her...

.NET 3.5 C# does not offer what I need for locking: Count async saves until 0 again.

I have some records, that I want to save to database asynchronously. I organize them into batches, then send them. As time passes, the batches are processed. In the meanwhile the user can work on. There are some critical operations, that I want to lock him out from, while any save batch is still running asynchronously. The save is don...

Command line semaphore utility

I want to write a command line utility that can be used to synchronize the execution off programs in different consoles. Console A: $ first_program && semaphore -signal Console B: $ semaphore -wait && second_program The first program takes a long take to complete. The second program can only start when the first program has finished...

Shared Memory and Process Sempahores (IPC)

This is an extract from Advanced Liniux Programming: Semaphores continue to exist even after all processes using them have terminated. The last process to use a semaphore set must explicitly remove it to ensure that the operating system does not run out of semaphores.To do so, invoke semctl with the semaphore identifier, the number of...

Locking semaphores in C problem sys/sem

Hi, EDIT: This peace of code is pretty fine (so take it as example of semaphores ;). Bug in my program was in another place - found by my friend. I have problem with my functions. Sometimes two processes enter into critical section. I can't find problem in this after I spent 10 hours by debugging. On what I should aim? Is there any pos...

C semaphores: sem_wait throwing inexplicable error

I'm working on a problem which we have to use semaphores to solve. I have an array which contains two semaphores, gsem, and given certain conditions call sem_wait(&(gsem[me])), which is supposed to waiting until that particular process is woken up. However, for some reason it gives me the error Bad file descriptor. I looked up sem_wait a...

Is there a way to find out the current count of a win32 semaphore?

I'm looking for a way with no side effects. Ideally, the following code would do the trick: long currentCount = 0; ::ReleaseSemaphore(h, 0, &currentCount); But unfortunately 0 is not allowed as the value of lReleaseCount, so the call returns FALSE. ...

Using boost locks for RAII access to a semaphore

Suppose I write a C++ semaphore class with an interface that models the boost Lockable concept (i.e. lock(); unlock(); try_lock(); etc.). Is it safe/recommended to use boost locks for RAII access to such an object? In other words, do boost locks (and/or other related parts of the boost thread library) assume that the Lockable concept w...

Real World Examples of read-write in concurrent software

I'm looking for real world examples of needing read and write access to the same value in concurrent systems. In my opinion, many semaphores or locks are present because there's no known alternative (to the implementer,) but do you know of any patterns where mutexes seem to be a requirement? In a way I'm asking for candidates for the s...

Named semaphores in Python?

Hi, I have a script in python which uses a resource which can not be used by more than a certain amount of concurrent scripts running. Classically, this would be solved by a named semaphores but I can not find those in the documentation of the multiprocessing module or threading . Am I missing something or are named semaphores not imp...

objective-c : @synchronized how it works ?

Hi, i have two methods -(void) a { @synchronized(self) { // critical section 1 } } -(void) b { @synchronized(self) { // critical section 2 } } now my question is if a thread is in critical section 1. will the critical section 2 be locked for other threads or other threads can access critical section 2. ...

Win32 Event vs Semaphore

Basically I need a replacement for Condition Variable and SleepConditionVariableCS because it only support Vista and UP. (For C++) Some suggested to use Semaphore, I also found CreateEvent. Basically, I need to have on thread waiting on WaitForSingleObject, until something one or more others thread tell me there is something to do. In...

Pros and cons with a ready-queue for diffrent semaphores in a mini OS.

In a OS we originally have a ready-queue for the threads, note only one queue. Why would it be better to have different queues for each semaphore. Pros and cons can be about efficiency, complexity or something else. ...

ubuntu: sem_timedwait not waking (C)

I have 3 processes which need to be synchronized. Process one does something then wakes process two and sleeps, which does something then wakes process three and sleeps, which does something and wakes process one and sleeps. The whole loop is timed to run around 25hz (caused by an external sync into process one before it triggers proces...

Memcache - How extend expiration of value with keeping consistency of value?

See this simple piece of code in PHP: //Documentation: //memcache_set ( string $key , mixed $var [, int $flag [, int $expire ]] ) //memcache_increment ( string $key [, int $value = 1 ] ) //part 1 memcache_set ( 'id' , 1 , 0 , 60 ); //part 2 $id = memcache_increment ( 'id' , 1 ); And now imagine that the incrementing "part 2" is call...

Reading and writing to SysV shared memory without synchronization (use of semaphores, C/C++, Linux)

Hi, I use SysV shared memory to let two processes communicate with each other. I do not want the code to become to complex so I wondered if I really had to use semaphores to synchronize the access to the shared memory. In my C/C++ program the parent process reads from the shared memory and the child process writes to the shared memory. ...

Using a named system semaphore as an event to trigger something in another process.

I have a thread that runs all the time: private void DoSomeStuffThread() { Semaphore sem = new Semaphore(0, 3, "sem_DoStuff"); sem.WaitOne(); do { //do some stuff } while (sem.WaitOne()); } I want to be able to only execute the stuff in the do block when something from another process says so. I am trying to use the "sem_DoStuff"...