What is a semaphore?
A semaphore is a programming concept that is frequently used to solve multi-threading problems. My question to the community: What is a semaphore and how do you use it? ...
A semaphore is a programming concept that is frequently used to solve multi-threading problems. My question to the community: What is a semaphore and how do you use it? ...
Is there any difference between binary semaphore and mutex or they are essentialy same? ...
What are the pros / cons of using pthread_cond_wait or using a semaphore ? I am waiting for a state change like this : pthread_mutex_lock(&cam->video_lock); while(cam->status == WAIT_DISPLAY) { pthread_cond_wait(&cam->video_cond, &cam->video_lock); } pthread_mutex_unlock(&cam->video_lock); Using a properly initi...
In VxWorks, I am creating a mutex with the SEM_INVERSION_SAFE option, to protect against the priority inversion problem. The manual says that I must also use the SEM_PRIORITY_Q option. Why is that? ...
We have 3 tasks running at different priorities: A (120), B (110), C (100). A takes a mutex semaphore with the Inversion Safe flag. Task B does a semTake, which causes Task A's priority to be elevated to 110. Later, task C does a semTake. Task A's priority is now 100. At this point, A releases the semaphore and C grabs it. We notice tha...
I want to prevent my script running more than once at a time. My current approach is create a semaphore file containing the pid of the running process read the file, if my process-id is not in it exit (you never know...) at the end of the processing, delete the file In order to prevent the process from hanging, I set up a cron job ...
Is there an advantage to using java.util.concurrent.CountdownLatch instead of java.util.concurrent.Semaphore? As far as I can tell the following fragments are almost equivalent: 1: final Semaphore sem = new Semaphore(0); for (int i = 0; i < num_threads; ++ i) { Thread t = new Thread() { public void run() { try { ...
A fairly basic question, but I don't see it asked anywhere. Let's say we have a global struct (in C) like so: struct foo { int written_frequently1; int read_only; int written_frequently2; }; It seems clear to me that if we have lots of threads reading and writing, we need a semaphore (or other lock) on the written_frequently me...
Is there any way to change the ownership and permission mask for a semaphore on Unix systems directly from the command prompt, without deploying a special program that calls semctl with the IPC_SET option? ...
I have two Slackware Linux systems on which the POSIX semaphore sem_open() call fails with errno set to 38. Sample code to reproduce below (the code works fine on CentOS / RedHat). Are there any kernel or system configuration options that could cause this? Other suggestions? Systems with issue are Slackware 10.1.0 kernel 2.6.11 /lib/li...
Hi, I am using the following code fragment in a php script to safely update a shared resource. $lock_id = sem_get( ftok( 'tmp/this.lock', 'r')); sem_acquire($lock_id) //do something sem_release($lock_id) When I stress test this code with large number of requests I get an error: Warning: semop() failed acquiring SYSVSEM_SETVAL for k...
I have a list wrapper that maintains two Tstringlists and a TClassList I need this to be thread safe, such that: Concurrent writes are not allowed (wait state of some sort should be entered) Reading while writing (or vice versa) is not allowed (wait state of some sort should be entered) Concurrent reads are allowed Any ideas on how ...
I'd like to use POSIX semaphores to manage atomic get and put from a file representing a queue. I want the flexibility of having something named in the filesystem, so that completely unrelated processes can share a queue. I think this plan rules out pthreads. The named posix semaphores are great for putting something in the filesystem...
What are the trade-offs between using a System V and a Posix semaphore? ...
Hello all, I am new here. I recently installed my video script to a new server but I am seeing that it will start to convert 1 video (via mencoder) then before finishing it, it will try and convery another, and another, so it will be trying to convert 4+ videos at the same time causing the server to shut down. The script developer said:...
How do i tell if one instance of my program is running? i thought i could do this with a data file but it would just be messy :( i want to do this as i only want 1 instance to ever be open at one point. Edit: Re-tagged ...
I have an IIS hosted WCF Service which uses SqlHelper class from DAAB version 2.0 in the data layer Once in a while, it throws exception at this line of ExecuteReader (a static method): Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader() Type: System.Runtime.InteropServices.COMException Message: The handle is invalid. (Excepti...
Is there such a thing as an atomic test-and-set, semaphore, or lock in Javascript? I have javascript invoking async background processes via a custom protocol (the background process literally runs in a separate process, unrelated to the browser). I believe I'm running into a race condition; the background process returns between my tes...
Is there a semaphone that works like a Chess timer, meaning; Thread A completes its task, loops back up to the top and calls the Semaphore This triggers Thread 2 which proceeds through its code, loops back up to the top and calls the Semaphore This triggers Thread A which... So the Semaphore is both blocking and signaling. I know I ...
Hello, I'm trying to learn the basic jist of a Semaphore in the Dining Philosopher problem. Right now, I have an array of class Chopstick, and each Chopstick has a semaphore with 1 available permit: public class Chopstick { Thread holder = null; private Semaphore lock = new Semaphore(1); public synchronized void take() thro...