Jump to content




[Question] Multithreading ?


  • You cannot reply to this topic
2 replies to this topic

#1 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 06 April 2014 - 02: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" ?

#2 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

Posted 06 April 2014 - 02: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.

#3 CometWolf

  • Members
  • 1,283 posts

Posted 06 April 2014 - 02: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users