Skip to content

Commit

Permalink
Playing with concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed Feb 28, 2011
1 parent 3063337 commit 58a5ac6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sudoku.erl
Expand Up @@ -29,19 +29,18 @@ solve_file(Filename, Seperator) ->

solve_all(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).
map(fun receiveSolution/1, PidGrids).

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

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

from_file(Filename, Seperator) ->
Expand Down

0 comments on commit 58a5ac6

Please sign in to comment.