JuliaLang/julia — pull request #6741 by tknopp (2014-05-04 08:14:33+00:00)
Title: WIP: Multithreading Experiment

This is an experiment on running Julia code in multiple threads (see #1790). While the code is certainly pretty broken I still like to get feedback whether the approach might be feasible.

The idea is to first precompile the function that is supposed to be run in the thread. To this end I use `jl_get_specialization`, which seems to do what I want. The hope is that the interaction with the Julia environment are minimal after precompilation so that race conditions are less likely to happen.

I have implemented two functions `parapply` and `parapply_jl` that take a function that is supposed to be run several times with the last argument being an index that covers a predefined range. While `par apply` implements the scheduling in C, `parapply_jl` implements it in Julia and exploits a direct thread API that is exposed to Julia. For the examples I have tried `parapply` works while `parapply_jl` crashes sometimes.

While this is a pretty naiv solution the real work is now to determine the places where race conditions can occur. Any help on this would be really appreciated.

This was developed on OSX with clang. For gcc one needs other compiler flags to enable c++11 threads.