This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mibac138's profile picture

[Question] Multithreading ?

Started by mibac138, 06 April 2014 - 01:03 PM
mibac138 #1
Posted 06 April 2014 - 03:03 PM
How to do something like, running 2 programs at once and if any will error then save the error to file (ex.) "/.log" ?
mrpoopy345 #2
Posted 06 April 2014 - 03:29 PM

function firstprogram()
 func, error = loadfile("testone")
 if not func then
  h = fs.open("log", "a")
  h.writeLine(error)
  h.close()
else
pcall(func)
end
end
function secondprogram()
 func, error = loadfile("testtwo")
 if not func then
  h = fs.open("log", "a")
  h.writeLine(error)
  h.close()
else
pcall(func)
end
end
parallel.waitForAll(firstprogram, secondprogram)
Untested, might not work. I am not so good with loadfile.
CometWolf #3
Posted 06 April 2014 - 03:38 PM
You forgot to log the error resulting from the file's execution(pcall). Im curious though, why would you need to do such a thing? My experience with the parallel API is limited, but wouldn't your program crash and display the error as normal if you did not do this? Logging it seems somewhat… redundant.