MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 430 forks source link

[1.11.2] in Thread API, os.sleep() or t:suspend() make thread eternal sleep #2518

Closed SangManLINUX closed 7 years ago

SangManLINUX commented 7 years ago

Hi. I'm a humble coder and also a fan of OpenComputers.

I was followed some document below here. http://ocdoc.cil.li/api:thread

After i read and follow this document by typing Lua code in minecraft, i encountered weird situation. Several functions make thread go to sleep and never wake up, for example os.sleep() and t:suspend(). So i tried to make clean minecraft modpack that includes only Minecraft, OpenComputers and Immersive Engineering for the power, but it happened same thing...

What is the problem? I wonder.

payonel commented 7 years ago

As always I need your oc version to provide further support. You have [1.11.2] in the title, which is partially helpful.

The thread api is wholly isolated to openos and is not affected by any other mods, no reason to test by removing mods.

Secondly, the thread api is fairly new and I would consider it in a 1.0 state. Better than alpha and beta, but not well baked.

Thirdly, I recently made some important fixes to the thread api, please download our latest dev builds: http://ci.cil.li/job/OpenComputers-dev-MC1.11/

purplemonday commented 7 years ago

-- the documentation doesnt always need tobe right depending what version your using it helps to mention witch version your using if you want a specific answer. -- thread api barely works. least for 1.7.10/openos 6.1/6.2

what does work if you want to multitask? coroutines and event style like functions and timers

payonel commented 7 years ago

woah woah ... i disagree with your comment a bit

  1. The documentation needs a lot of work, sure, but if the documentation is wrong then we have a bug and it can be reported here
  2. thread api works very well. please if you have a bug to report with our new threads please let me know. I am happy fix it. The thread api is one of my most favorite libraries in openos

"That's basically the only thing that works if you want to multitask" -- is false, threads are pretty amazing and I will continue to improve them when people find any issue with them. Sure they are new, but I will definitely continue to improve them

payonel commented 7 years ago

Note that when I say threads are at a "1.0 state" I am including the recent patch. The first builds with the thread api had many issues that I've worked out. I have no known issues with the thread api at this time

purplemonday commented 7 years ago

for 1.7.10 it never did openos 6.1/6.2 crazy things i did trying to make it work.. i feel attacked.

payonel commented 7 years ago

I apologize, I don't want anyone to feel attacked. I only felt it was important to correct the conversation and not give the impression that threads can't be used. Threads are great, and I am fully committed to making them reliable and amazing.

But can you [ @purplemonday ] help me understand what you meant?

for 1.7.10 it never did openos 6.1/6.2

What is "it", and what did it never do? Does this mean

  1. You never used openos 1.6.1 or 1.6.2? Have you ever used the new thread api? http://ocdoc.cil.li/api:thread . Threads were added in openos 1.6.4 June 9th 2017 [ though it has improved since that first realse ]
  2. Or are you saying threads never worked in in OC 1.6.1? Again, openos has moved through a minor version set from 1.6 to now 1.6.8. Threads were introduced in 1.6.4 and are much improved since then.

crazy things i did trying to make it work

  1. Did you try to fix /lib/thread api? What things did you try doing? Are there any bugs you have to report from that?
  2. Or are you saying you tried to make your own multitasking framework on top of the event library? What were your ideas/attempts?

And very important -- what type of application were you trying to make? I would be interested in measuring the thread api against your use case -- this discussion could perhaps help me improve the thread model I built for openos

payonel commented 7 years ago

@SangManLINUX also, i would need some sample code that repro's this problem thanks

SangManLINUX commented 7 years ago

I'm sorry about that i forgot to mention the version of OpenComputers i downloaded from Curse. It's OpenComputers-MC1.11.2-1.7.0.40.jar

According your advise, i downloaded newer version of OpenComputers from jenkins. Now it's OpenComputers-MC1.11.2-1.7.0.44.jar

Finally now i can see that thread api is working well as doc said.

The wired problem that i saw is with example code from your doc. http://ocdoc.cil.li/_export/code/api:thread?codeblock=8

This code makes output below before. But with newer version it's worked as doc said. /// start outside thread create after suspend after resume ///

Another example is. http://ocdoc.cil.li/_export/code/api:thread?codeblock=14

This code makes output below before. But now it's working well. /// before sleep suspended suspended after resume running -- and the program never end ///

I think this example's output in doc should be modified. Because the child thread's resume is too fast so main thread can not get the child thread's death. I saw the child thread is dead by adding os.sleep() in main thread code. And also there is no "after sleep".

payonel commented 7 years ago

"But with newer version it's worked as doc said", and "But now it's working well" So it sounds like this bug can be closed?

I've also retested the code samples you linked on our latest builds and I can confirm that they work as documented.

payonel commented 7 years ago

I think this example's output in doc should be modified. Because the child thread's resume is too fast so main thread can not get the child thread's death. I saw the child thread is dead by adding os.sleep() in main thread code. And also there is no "after sleep".

Yes, but that was before the latest build which fixes this. I also added more sleeps and I confirmed it correctly prints the "after sleep"

SangManLINUX commented 7 years ago

Thank you for your attention.

I am always thankful for your mod.

Happy modding.