Skip to content

Commit

Permalink
First stab at concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed Feb 28, 2011
1 parent 94d8a5f commit 3063337
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sudoku.erl
Expand Up @@ -28,7 +28,21 @@ solve_file(Filename, Seperator) ->
Solutions.

solve_all(GridList) ->
map(fun time_solve/1, GridList).
PidGrids = [{spawn(fun server/0), Grid}|| Grid <- GridList],
Pids = [Pid || {Pid, _} <- PidGrids],
map(fun({Pid, Grid}) -> Pid ! {self(), solve, Grid} end, PidGrids),
map(fun receiveSolution/1, Pids).

receiveSolution(Pid) ->
receive
{Pid, Puzzle} -> Puzzle
end.

server() ->
receive
{From, solve, GridString} ->
From ! {self(), time_solve(GridString)}
end.

from_file(Filename, Seperator) ->
{ok, BinData} = file:read_file(Filename),
Expand Down

0 comments on commit 3063337

Please sign in to comment.