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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

(- ( vector-length vec ) 1)<br />

( self ))<br />

( recv ( msg ( where ( eqv msg ( self )))))))<br />

( let ((v ( make-vector-iota 6)))<br />

( newline )<br />

( print "após iota : " v)<br />

( newline )<br />

( vector-shuffle ! v)<br />

( print "após suffle !: " v)<br />

( newline )<br />

( let ((w ( vector-copy v )))<br />

( quicksort ! w)<br />

( quicksort-par ! v)<br />

( print "w após quicksort !: " w)<br />

( newline )<br />

( print "v após quicksort-par !: " v)<br />

( newline )))<br />

após iota: 012345<br />

após suffle!: 421035<br />

w após quicksort!: 012345<br />

v após quicksort-par!: 012345<br />

Esta implementação do Quicksort concorrente só funciona quando as threads estão na<br />

mesma CPU e <strong>com</strong>partilhando o vetor (portanto é uma implementação mista do modelo<br />

Actor <strong>com</strong> memória <strong>com</strong>partilhada).<br />

exercícios<br />

Ex. 96 — Implemente uma macro parallel, usando o procedimento par, de forma que<br />

seja possível usar livremente parallel e begin, <strong>com</strong>o se faz <strong>com</strong> PAR e SEQ em occam:<br />

( parallel<br />

( begin<br />

( set ! a 2)<br />

Versão Preliminar<br />

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

305

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

Saved successfully!

Ooh no, something went wrong!