thumbnail

Semafory

Quiz by
Hralyb
Rate:
Last updated: May 14, 2025
You have not attempted this quiz yet.
First submittedMay 14, 2025
Times taken7
Average score80.6%
Report this quizReport
30:00
Enter answer here
0
 / 62 guessed
The quiz is paused. You have remaining.
Scoring
You scored / = %
This beats or equals % of test takers also scored 100%
The average score is
Your high score is
Your fastest time is
Keep scrolling down for answers and more stats ...
Hint
Answer
Deklarace
struct Semaphore{
 
int value;
 
queue *q;
 
bool locked;
 
};
Inicializace
void init(struct Semaphore *s, unsigned value){
 
s->value = value;
 
s->locked = false;
 
}
Lock Swap
void lock(struct Semaphore *s){
 
bool key = true;
 
while(key == true){
 
swap(&(s->locked), &key);
 
}
 
s->value--;
 
if(s->value < 0){
 
process_t *p = get(ready_q);
 
append(s->q, p);
 
s->locked = false;
 
switch();
 
}
 
else
 
s->locked = false;
}
Unlock Swap
void unlock(struct Semaphore *s){
 
bool key = true;
 
while(key == true){
 
swap(&(s->locked), &key);
 
}
 
s->value++;
 
if(s->value <= 0){
 
process_t *p = get(s->q);
Hint
Answer
 
append(ready_q, p);
 
s->locked = false;
 
}
 
else
 
s->locked = false;
 
}
Lock TandS
void lock(struct Semaphore *s){
 
while(TandS(s->locked))
 
while(s->locked);
 
s->value--;
 
if(s->value < 0){
 
process_t *p = get(ready_q);
 
append(s->q, p);
 
s->locked = false;
 
switch();
 
}
 
else
 
s->locked = false;
 
}
Unlock TandS
void unlock(struct Semaphore *s){
 
while(TandS(s->locked))
 
while(s->locked);
 
s->value++;
 
if(s->value <= 0){
 
process_t *p = get(s->q);
 
append(ready_q, p);
 
s->locked = false;
 
}
 
else
 
s->locked = false;
 
}
Save Your Stats
Your Next Quiz
Name all 50 states in the USA. Easy, right?
Can you name the capitals cities of all 196 countries in the world?
Drag the flag onto the correct country. Careful, though! One wrong move and the game ends.
Can you spell out the name of the US state by guessing letters? Watch yourself! After 4 incorrect guesses, you're fully on the "gallows"!
Comments
No comments yet