-
Notifications
You must be signed in to change notification settings - Fork 2
Leitura de args + n max threads #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
71c094e
ciclo infinito
Ca-moes bf06208
?
Ca-moes 14a191f
many CLOSD
Ca-moes 204a800
enunciado
Ca-moes f3b32ff
Só 1 closd, no 2LATE
Ca-moes f8e8d99
Leitura de argumentos
Ca-moes 169a01c
Tem NONBLOCK, programa dá BLOCK, fuck this
Ca-moes 89a094f
-n tratado
Ca-moes 688cd9e
retirar linhas de debug
Ca-moes 9bbbbd8
fixed thread number bug
filiperecharte 8051302
Update src2/Q2.c
Ca-moes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #!/bin/bash | ||
| cd src/tmp | ||
| cd src2/tmp | ||
| rm fifoname |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aqui acho que não precisamos deste else, ele simplesmente fica a correr este ciclo while para se manter aberto até acabar o tempo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concordo, quando o if se tornar false fazer cleanup, por isso basta mudar para um while
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok estava a pensar e talvez tenha mesmo que ser um if na mesma, porque pode acontecer haver o máximo de threads ativas ao mesmo tempo (pouco provável acho, mas pode acontecer)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Para chegar a esse else quer dizer que há um pedido mas não existem threads para o atender. Na thread do cliente este vai conseguir excrever no fifo público, fazer o fifo privado e abrir o fifo privado (porque tem NONBLOCK) . Quando tentar ler do fifo é que irá dar erro devido a esta parte :
Que acho que é a estratégia que faz sentido. Tendo em conta que é uma casa de banho, se for feito um pedido e não houver ninguém para "atender" o cliente tem de tentar mais x vezes e voltar mais tarde.
E.G. Se a casa de banho de S.Bento não tivesse torniquete, só a senhora a verificar as senhas. Se chegar lá um gajo que quer mandar o Obama à casa branca e não tiver lá a senhora ele fica um tempo à espera e depois vai embora, para retornar mais tarde ou ir a outro sitio.
Outra estratégia seria guardar o pedido numa fila para assim que houver o thread disponivel tratar desse pedido, mas a fila já está meio implícita nas tentativas que a thread client faz.
Mais 2 coisas:

1º
Este se não houver lugares diponiveis é dentro de cada thread que se vai verificar, não engloba este problema.
2º

Vi isto no enunciado e acho que estamos meio lixados. Da forma que está agora como está a fazer a verificação no read por tentativas não está garantido que terá sempre uma resposta. Da forma que está agora serve para caso haja algum erro (de escrita ou leitura dos fifos) que não cause o término do programa de forma inesperada, mas não assegura esta condição :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isso quer dizer que o nthreads é o nthreads em simultâneo? E o cliente tem de esperar que hajam threads disponiveis para o atender? Damn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, em simultâneo não pode haver mais do que nthreads ativas
Quanto ao cliente é que não tenho a certeza. Acho que o objetivo é ter o servidor a tratar de mais trabalho em vez de pôr o cliente a pensar quando pode fazer pedidos ou não.
Acho que o cliente apenas faz pedidos e não se interessa se existem threads para o atender ou não, se houver -> fixe, pedido atendido, se não houver -> FAILD . Acho que não há problema com a parte do "se não houver" porque estão a ser feitos "pedidos" e não "clientes" novos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pois faz sentido, os pedidos podem ser da mesma pessoa, o cliente nao tem de saber quando fazer o pedido, simplesmente faz e pronto depois vê se consegue ser atendido ou não, acho q ta bem assim