📘 Parallel file processing in Perl 6

Process the files from the current directory in a few parallel threads. We have to do something with each file in the directory, and it has to be done in such a way that files are processed independently with a few workers. It is not possible to predict how long the process will take for … Continue reading “📘 Parallel file processing in Perl 6”

📘 Atomic operations in Perl 6

Using the solution for Task 38, the Monte Carlo method, create a program that calculates the result using multiple threads. Perl 6 has built-in support for parallel computing. In Task 92, Sleep Sort, we’ve seen how to use the keywords await, gather, and take to spawn a few threads and wait for them to finish.  When different threads want to … Continue reading “📘 Atomic operations in Perl 6”

📘 Sleep Sort in Perl 6

Implement the Sleep Sort algorithm for a few small positive integer values. The Sleep Sortis a funny implementation of the sorting algorithm. For each input value, an asynchronous thread starts, which waits for the number of seconds equals to the input number and then prints it. So, if all the threads are spawned simultaneously, the output … Continue reading “📘 Sleep Sort in Perl 6”

📘 Setting timeouts in Perl 6

Do not wait for a slow code block if it takes too long. In Perl 6, promises are the best way to create timeouts. In the following example, two code blocks are created; they are executed in parallel. my $timeout = Promise.in(2).then({    say ‘Timeout after 2 seconds’;});my $code = start {    sleep 5;    say ‘Done after 5 seconds’;} … Continue reading “📘 Setting timeouts in Perl 6”