Page 2 of 2

Re: How works love.threads?

Posted: Fri Jun 16, 2017 4:10 pm
by NoAim91
@zorg: yeah, the print doesn´t work ... and it should not return 10, it should return 13.... I guess the output = c1:demand() takes the c1:push(input) befor the thread input = c1:demand() can take the variable.

Re: How works love.threads?

Posted: Fri Jun 16, 2017 6:59 pm
by bartbes
That's probably what happens. You can have the main thread wait until the message has been delivered by using supply instead of push. And of course make sure you do that after starting the thread.

Re: How works love.threads?

Posted: Fri Jun 16, 2017 8:54 pm
by NoAim91
okay, I thought I could solve my problem with threads, but it doesn´t work.

My problem -> game freeze because the for loop is too big.

Code: Select all


function love.load()
  t     = love.thread.newThread("thread.lua")
  c1    = love.thread.newChannel()

  input = 10000
  output = 0

function love.update(dt)
  if not t:isRunning() and output == 0 then output = c1:demand()  print(output) end

Code: Select all

local c1 = ...

input = c1:demand()

function test(input)
  a = {}
    for i=1, input do
     a[i] = {}
      for j=1, input do
        a[i][j] = 0
  return a

output = test(input)
basicly it is not possible to create a table with 10.000 x 10.000 entrys with one for loop?! I ask this question because I like to create big procedural generated worlds with the love.math.noise function... But If I make a cut after 1000x1000 and go for the next 1000x1000 than my world gets a scar :-/

Re: How works love.threads?

Posted: Fri Jun 16, 2017 11:13 pm
by zorg
It's much more likely that you just deadlocked your program with both threads waiting for one another in some way.

Re: How works love.threads?

Posted: Sat Jun 17, 2017 7:29 am
by NoAim91
@zorg: nope. The thread starts and the main thread should update itself while the thread is doing its thing ... its not directly waiting.

If I use 1.000 as input it works. The Table is created with 1000x1000 entrys. But If I choose 10.000 it dies.

However ... I could need something which prevents the freezing