Jump to content
misteriosa

Duvida numa palavra

Recommended Posts

misteriosa

Eu tenho este programa e gostava de saber o UP e o DOWN o k significam?

Obrigada

  while (true) { 
DOWN(passageiro) 
entra_no_carrinho()  /* vários passageiros podem entrar “ao mesmo tempo” */
DOWN(mutex) 
Npass++ 
if (Npass == C) {   /* carrinho lotou */ 
    UP(carrinho)  /* autoriza carrinho a andar */ 
     DOWN(andando)    /* espera carrinho parar */ 
     UP(mutex) 
} 
  else { 
  UP(mutex) 
DOWN(andando)    /* espera carrinho lotar, passear e voltar */ 
    } 
  }     
} 

Share this post


Link to post
Share on other sites
Localhost

Provavelmente são funções que foram definidas anteriormente.


here since 2009

Share this post


Link to post
Share on other sites
Baderous

http://en.wikipedia.org/wiki/Semaphore_%28programming%29#Semantics_and_Implementation

Neste link, as operações P e V são o down e o up, respectivamente.

Operation V increments the semaphore S, and operation P decrements it.

No teu caso, estás a trabalhar com um mutex, que é um semáforo com valor 1, ou seja, um semáforo binário (com uma ligeira diferença):

The mutex is similar to the principles of the binary semaphore with one significant difference: the principle of ownership. Ownership is the simple concept that when a task locks (acquires) a mutex only it can unlock (release) it. If a task tries to unlock a mutex it hasn’t locked (thus doesn’t own) then an error condition is encountered and, most importantly, the mutex is not unlocked. If the mutual exclusion object doesn't have ownership then, irrelevant of what it is called, it is not a mutex.

http://stackoverflow.com/questions/62814/difference-between-binary-semaphore-and-mutex

Share this post


Link to post
Share on other sites
Baderous

Acho que não é muito difícil perceber isso depois do meu último post. Mas também se olhares para o nome das funções pode ser que fique mais fácil.

P = down = decrementa

V = up = incrementa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.