08.02.2015 Views

Programação Funcional e Concorrente com Scheme

Programação Funcional e Concorrente com Scheme

Programação Funcional e Concorrente com Scheme

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

notas de aula - Jerônimo C. Pellegrini<br />

;; procedimento, é boa prática dar-lhe algum valor antes:<br />

( define pong #f)<br />

( define ping<br />

( coroutine value resume<br />

( write-line " PING 1")<br />

( resume pong value )<br />

( write-line " PING 2")<br />

( resume pong value )<br />

( write-line " PING 3")<br />

( resume pong value )))<br />

( define pong<br />

( coroutine value resume<br />

( write-line " Pong 1")<br />

( resume ping value )<br />

(ping ’hello)<br />

PING 1<br />

Pong 1<br />

PING 2<br />

Pong 2<br />

PING 3<br />

Pong 3<br />

hello<br />

( write-line " Pong 2")<br />

( resume ping value )<br />

( write-line " Pong 3")<br />

( resume ping value )))<br />

As linhas são mostradas alternadamente pelas duas threads; a última linha é o valor<br />

de retorno de ping. A figura a seguir ilustra a extensão dinâmica das duas co-rotinas.<br />

Versão Preliminar<br />

[ 27 de outubro de 2010 at 15:47 ]<br />

209

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!