Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Problem with threads


Hello, Im currently working on a programm to controll SGCrafts stargates.

Im trying to run multiple operations:

* Reading inputs from User

* check for an open connection (and send a redstone signal it it connected)

But its not working.

thread = require("thread")

function check()
	while(true) do
		-- Check and manage the signal

function userInput()
	while(true) do
		-- Process inputs


What is the Problem? When I start the first loop the other wont get started. (The same problem with coroutines)

So my Questions:

1) Is there any way to get this working?

2) (if not) is there any way to process code while waiting for an userinput via io.read()?


Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Lua is single threaded. Meaning that only one chunck of code can ever run at a time. Coroutines are considered co-operative in that they yield to allow others to compute before they themselves finish. The idea is that we can do a little work we need right now and do it quickly, then yield so others can do the same, hence co-operative. Threads are fancy coroutines, but they are still limited to cooperation, so they must yield if you wish to begin another. Use term.read or io.read or os.sleep.... etc. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.