Task.WaitAll and Exceptions

Can’t reproduce this – it works fine for me: using System; using System.Threading; using System.Threading.Tasks; class Test { static void Main() { Task t1 = Task.Factory.StartNew(() => Thread.Sleep(1000)); Task t2 = Task.Factory.StartNew(() => { Thread.Sleep(500); throw new Exception(“Oops”); }); try { Task.WaitAll(t1, t2); Console.WriteLine(“All done”); } catch (AggregateException) { Console.WriteLine(“Something went wrong”); } } } … Read more

Why do we need ‘seq’ or ‘pseq’ with ‘par’ in Haskell?

Ok. I think the following paper answers my question: http://community.haskell.org/~simonmar/papers/threadscope.pdf In summary, the problem with a `par` b `par` a+b and a `par` a+b is the lack of ordering of evaluation. In both versions, the main thread gets to work on a (or sometimes b) immediately, causing the sparks to “fizzle” away immediately since there … Read more

What’s the best way to update an ObservableCollection from another thread?

If you initialize the collection in the constructor it will be on the default Application thread. To invoke the main thread you can do this: Application.Current.Dispatcher.Invoke((Action)(() => { //Do something here. })); You have to cast the Anonymous delegate as an action otherwise it gets confused ¯\O_o/¯ If you are using the Async CTP then … Read more

Conversion from scala parallel collection to regular collection

As you go explicitly from sequential to parallel collection via .par, you go back to sequential via .seq. Since sets and maps have parallel implementations, toMap and toSet calls leave the collection in the current domain. The example of reduce works because it, well, reduces the collection (the outer ParSeq disappears, leaving you with the … Read more

Java 8 parallel sorting vs Scala parallel sorting

One can implement a parallel sort in scala e.g. http://blog.yunglinho.com/blog/2013/03/19/parallel-external-merge-sort/ . I don’t know why ParSeq doesn’t offer sorting in its API. Note that there are a number of alternatives to .par, so don’t necessarily assume that your results from ParSeq are representative of Scala parallelism in general. (But benchmarks are valuable and I wish … Read more

How do Java 8 parallel streams behave on a thrown exception?

When an exception is thrown in one of the stages, it does not wait for other operations to finish, the exception is re-thrown to the caller. That is how ForkJoinPool handles that. In contrast findFirst for example when run in parallel, will present the result to the caller only after ALL operations have finished processing … Read more

Use cases for ithreads (interpreter threads) in Perl and rationale for using or not using them?

The short answer is that they’re quite heavy (you can’t launch 100+ of them cheaply), and they exhibit unexpected behaviours (somewhat mitigated by recent CPAN modules). You can safely use Perl ithreads by treating them as independent Actors. Create a Thread::Queue::Any for “work”. Launch multiple ithreads and “result” Queues passing them the (“work” + own … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)