Questions tagged [binary-semaphore]

43 questions
983
votes
36 answers

Difference between binary semaphore and mutex

Is there any difference between a binary semaphore and mutex or are they essentially the same?
Nitin
  • 15,151
  • 8
  • 23
  • 14
4
votes
2 answers

Hoare Monitor implementation using semaphores?

it is my exam in 4 days and I just spoke to my lectuer and he has been extremely unclear about this part of the lecture and I really struggled along with many students how to understand this. Basiclly, if you wanna implement Hoare monitor using…
3
votes
1 answer

Making binary semaphore shared between multiple processes(not threads , Process Only) using POSIX in C language

i am making binary semaphore shared between multiple processes(not threads , Process Only) using POSIX in C language. if i create binary semaphore using mutex, typedef struct BIN_SEMA { pthread_cond_t cv; /* cond. variable …
KrunalParmar
  • 1,062
  • 2
  • 18
  • 31
2
votes
2 answers

error: too many initializers for ‘std::array, 4>’

The below code snippet does not compile. I tried different initializers but could not make it compile. #include #include int main() { std::array semaphores { {0}, {0}, {0}, {0} }; auto& […
digito_evo
  • 3,216
  • 2
  • 14
  • 42
2
votes
1 answer

Controlling thread order using semaphores in C

I'm new to C and I'm just trying to run this piece of code of Pacheco's book "An Introduction to Parallel Programming". And I just can't figure out how I should implement the semaphores initialization in main(). Are &semaphores[dest] and…
Jakub Badacz
  • 63
  • 1
  • 7
2
votes
2 answers

How to set POSIX semaphore value to 1?

I am implementing semaphore in c language.I have a POSIX counting semaphore. I want to assign a value to it. and i don't want to use Wait or Post. Can i do that? Is there any function like "setValue" for POSIX Semaphore ?
KrunalParmar
  • 1,062
  • 2
  • 18
  • 31
1
vote
0 answers

Synchronize parent and forked process using POSIX named semaphores to print in text file

I want to print numbers from 1 to 99 in a text file where: parent process prints odd numbers. child process prints even numbers. Here is what I've…
yazzy
  • 36
  • 3
1
vote
1 answer

Implementing a semaphore through a file

thank you for taking your time to read this. I'm trying to implement a semaphore through a file using C on a linux machine. I have two process that I must synchronize, one has all the consonants of a file stored in an array, the other has all the…
Maridiama
  • 11
  • 2
1
vote
0 answers

Single use condition_variable

Consider this simple synchronization problem. I have two threads, A and B, that each execute 2 steps. I want step 1a to be performed before step 2b. Thread A Thread B Step 1a Step 1b Step 2a Step 2b I have some options for how to…
1
vote
0 answers

operating issues qustions - threads, processes etc. for the above code:

int S1 = 0; int S2 = 0; int x = 0; int run = 1; void Producer(void) { while(run) { while (S1 == S2); x++; __sync_synchronize(); S1 = S2; __sync_synchronize(); } } void Consumer(void) { while(run) { while (S1 !=…
1
vote
1 answer

Avoid taking a long time to finish the 'too much milk' scenario

The following is a simple solution to the 'too much milk problem' lock mutex; while (1){ lock_acquire(mutex); if (no milk) go and buy milk;//action-1 lock_release(mutex); } The problem is that,…
Nht_e0
  • 140
  • 4
  • 15
1
vote
1 answer

The futex facility returned an unexpected error code and Aborted

I am trying to solve the Philosophers Dining Problem using semaphores. The philosopher first picks up the left fork and then right fork and when finished eating puts them down. I am implementing this using 5 threads one for each philosopher and 5…
1
vote
2 answers

Implementing Counting-Semaphore Using Binary-Semaphore

I have implemented sort of user level threads system.I need some help with implementation of a counting semaphore, using binary semaphore implementation(up and down functions as described below). Here is the interface of my implementation of a…
David
  • 733
  • 2
  • 11
  • 30
1
vote
0 answers

threads and semaphore in c

good morning, i try to execute 2 threads t1 and t2 by using the semaphore c library. I wrote this code #include #include #include #define Max 100; int cpt=0; sem_t mutex; void* count(void* data) { int i; …
1
vote
2 answers

Starvation in test and set instruction

The following question has been asked in GATE Exam: The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows: void enter_CS(X) { while test-and-set(X) ; } void…
1
2 3