I must admit that I find it hard to create syntax supporting parallelism that I like and does what I want. I have looked into other languages for ideas, but the solutions are either too implicit or to manual. I insist on having a syntax that force us to write code in a way that automatically will solve the technical issues involved – and yet provide us with an option to manually control things if we need to – and I insist on code being readable.
My previous example uses “Spawn” to mark a statement or block that we execute in background. I used this on transaction, but we could in theory apply that as a prefix/postfix to any statement to create a background process. I need the background process because I need the logic that control and respond to a remote function Call that is not blocking.
for x=1 to 20 spawn transaction arr[x] arr[x] = Compute(x) state (Compute) on Error(..) // todo end update end
If I limit this to transaction I also force the usage of a mechanism that will sort out the multi-threading issues and using spawn as a prefix (or postfix maybe) to transaction avoid that we need to create a new control mechanism.
The challenge here is that I will be allowing 20 background processes while I continue executing the foreground process – so we will have 21 VM’s active with a bit of code. At some point we might need to collect those process and wait until they are all completed as well as respond to error situations.
Parallel( timeout=10000) for x=1 to 20 spawn Math[x] transaction arr[x] arr[x] = Compute(x) state (Compute) on Error(..) // todo end update end On Timeout() // On Synchronize // End
My first proposal was Parallel..end. End will not work so I replace it with “Synchronize”. – just playing around with ideas here – but using our new State mechanism might be an idea except that “State” is already used for a purpose. I can however use implicit state and allow Parallel to be a function where we allow the main code block to be embedded inside a function. I will need added syntax to functions, but this would allow us to treat timeout and synchronize as events + give us a powerfully new mechanism to actually create new control structures in Plain itself.