semaphore

Linux synchronization with FIFO waiting queue

Are there locks in Linux where the waiting queue is FIFO? This seems like such an obvious thing, and yet I just discovered that pthread mutexes aren't FIFO, and semaphores apparently aren't FIFO either (I'm working on kernel 2.4 (homework))... Does Linux have a lock with FIFO waiting queue, or is there an easy way to make one with exis...

Semaphores in a single thread

Hello, I was wondering whether it would ever make sense to use a mutex or semaphore when there is only one thread?. Thanks for your help. ...

sem_t union/struct C++ inherintance

I'm porting some old C++ project on Linux (RHEL 5.3). The situation is the following #include <semaphore.h> class OldClass: public sem_t This used to work because till glibc-2.3.3.20040420 sem_t was a struct. Now, with the newer version of glib is a union =>inheritance not allowed. so the compilation doesn't work. how it was: type...

Difference between sem_init and sema_init

What is the difference between sema_init and sem_init ? Are there any specific usage scenarios and other dependencies for the respective APIs ? ...

Mac OS X : boost interprocess semaphore timed_wait : Abnormal CPU consumption

Hi. After porting a code segment from Windows to Mac OS X, I found it to consume a whole CPU core while running; the responsible call for the CPU consumption is boost::interprocess::interprocess_semaphore::timed_wait. Here follows the code portion which reproduces this behaviour. #include <boost/interprocess/sync/interprocess_semaphore...

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 ...

semaphore related - smtctl use IPC_RMID failed with Invalid argument

If I do not define LINUX_ENV macro,everything goes well(especially,the IPC_RMID cmd return 0). but if I define LINUX_ENV(I am running on linux system-ubuntu10.04),the last semctl's IPC_RMID cmd return EINVAL,and says Invalid argument, i.e. the semaphore is not removed. it seems earlier semctl SEM_INFO cmd causes later IPC_RMID cmd return...

Why did POCO chose to use Posix semaphores for OSX?

I am a new bee to MAC/OSX. I am working on Titanium a cross platform runtime, which uses POCO library for most of the portable C++ API. I see that POCO uses POSIX semaphore for its NamedMutex implementation on OSX as opposed to SysV semaphore that it is using for few other *NIX. bool NamedMutexImpl::tryLockImpl() { #if defined(sun) || ...

Semaphore with priority

I know about the Semaphore class in the System.Threading namespace, but I don't see if it allows waiting threads to have different priorities levels. If two threads are waiting for an open slot, is there a way to allow the thread with the higher priority to have the first open slot available? ...

Does using a lock has better performance than using a local (single application) semaphore ?

Does using a lock has better performance than using a local (single application) semaphore? I read this blog from msdn : Producer consumer solution on msdn and i didn't like their solution to the problem because there are always 20 elements left in the queue. So instead, i thought about using a Semaphore that will be available only in...

Incrementing the value of POSIX semaphores by more than 1

I have this requirement wherein I have to increment the value of a POSIX semaphore by more than 1. Apparently, there is no way in POSIX specification to do this. There is no sem_setvalue() similar to sem_getvalue(). I do not want to go back to System V semaphores just because of this constraint. Is there any alternative way to acco...

php multithreading problem

I am writing a php cron job that reads thousands of feeds / web pages using curl and stores the content in a database. How do I restrict the number of threads to, lets say, 6? i.e., even though I need to scan thousands of feeds / web pages, I want only 6 curl threads active at any time so that my server and network don't get bogged down....

what is the difference between semaphore and critical region?

the only thing i understood is semaphore is a primitive way critical region has a GUARD variable (semaphore also does but the name is not GUARD!) ?? so whats the difference? ...

Why is this code failing under valgrind (helgrind)?

...

In VB.NET, wait for a Timer Or a KeyPress

I have a console application which is intended to just keep running until it is killed. Essentially: <setupCode> Do <doProcessing> Thread.Sleep(<interval>) Loop Essentially this will keep running until the user kills it, obviously. What I'd like to do is replace the Thread.Sleep call with a wait-condition waiting on eith...

Performance test: sem_t v.s. dispatch_semaphore_t and pthread_once_t v.s. dispatch_once_t

I wanted to know what would be better/faster to use POSIX calls like pthread_once() and sem_wait() or the dispatch_* functions so I created a little test and am surprised at the results (questions and results are at the end). In the test code I am using mach_absolute_time() to time the calls. I really dont care that this is not exactl...

CMU: Semaphores!

Check My Understanding of semaphores, please! I understand the idea behind counting semaphores and binary semaphores. However the difference between a spinlock and semaphore implemented with signal() and wait() kind of blend together to me. For example a spinlock has basically two values (a binary true/false for locked or unlocked). ...

sem_wait not working as expected?

Follow up question to my pervious question: http://stackoverflow.com/questions/3579860/conditional-wait-with-pthreads I changed my code to use semaphores instead of mutex locks and conditional signals. However, I seem to have run in to a condition that I cannot explain. Here is the abstract function thread work { while (true) s...

How to explain semaphore processing operation?

Next is a simple semaphore implementation. public class Semaphore { private boolean signal = false; public synchronized void take() { this.signal = true; this.notify(); } public synchronized void release() throws InterruptedException { while (!this.signal) wait(); this.signal = false; } } Is it true, that by c...

How can I code a monitor in C?

Hello, I need to do some process synchronization in C. I want to use a monitor, and I have read a lot about them. However I have been unable to find out how to implement one in C. I have seen them done in Java and other languages like C++, but I am unable to find examples in C. I have looked through K&R and there is no example in there...