Is Love.update reentrant?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
MrEricSir
Prole
Posts: 12
Joined: Fri Sep 02, 2011 12:37 am

Is Love.update reentrant?

Post by MrEricSir »

Is the Love.update() function assumed to be reentrant? Is it possible for this function to be called from multiple threads?

I ask because in the binary module I'm developing I have a function getting called from every Love.update(). There was a bug that I fixed more or less by accident when I added a reentrancy guard.

I'm running Love 0.7.2 on Ubuntu Natty, if that helps.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Is Love.update reentrant?

Post by miko »

MrEricSir wrote:Is the Love.update() function assumed to be reentrant? Is it possible for this function to be called from multiple threads?
love.update() is assumed to be global singleton - it updates the state of the program, so every frame you call it just once. This is the design decision to help you as a programmer write better code.
Threads, OTOH, are meant as a helper workers for doing cpu-intensive tasks without slowing down the main thread (which means GUI - ie, how fast the program responds to user input). Read more about threads here:
http://love2d.org/wiki/love.thread
MrEricSir wrote:I ask because in the binary module I'm developing I have a function getting called from every Love.update(). There was a bug that I fixed more or less by accident when I added a reentrancy guard.

I'm running Love 0.7.2 on Ubuntu Natty, if that helps.
You can do it, but it is against a good practice. Following this way is asking for troubles. So in short: don't do that.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is Love.update reentrant?

Post by slime »

love.update is a function that by default gets called once per frame by LÖVE, if it has been defined by you. Every thread is a separate instance of Lua which doesn't contain the main loop by default, so you can't technically call love.update from multiple threads, besides writing a separate loop and love.update function for each thread.
MrEricSir
Prole
Posts: 12
Joined: Fri Sep 02, 2011 12:37 am

Re: Is Love.update reentrant?

Post by MrEricSir »

Guess I wasn't very clear with my original question... I'm not asking if I should call Love.update(); I'm not that crazy!

Rather I want to know if there's ever a case where Love itself will call Love.update() from outside the main thread and/or concurrently from the same thread (main or otherwise.)
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Is Love.update reentrant?

Post by TechnoCat »

MrEricSir wrote:Guess I wasn't very clear with my original question... I'm not asking if I should call Love.update(); I'm not that crazy!

Rather I want to know if there's ever a case where Love itself will call Love.update() from outside the main thread and/or concurrently from the same thread (main or otherwise.)
Maybe this will interest you? love.run
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Is Love.update reentrant?

Post by T-Bone »

MrEricSir wrote:Guess I wasn't very clear with my original question... I'm not asking if I should call Love.update(); I'm not that crazy!

Rather I want to know if there's ever a case where Love itself will call Love.update() from outside the main thread and/or concurrently from the same thread (main or otherwise.)
I believe it's called from the "main thread" (from love.run(), that is). If you want to change the flow, overwrite love.run().
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Is Love.update reentrant?

Post by bartbes »

Since nobody seems to have noticed slime's post, I shall redirect you there, he's right.
Another thread can't call love.update, because it doesn't exist there.
MrEricSir
Prole
Posts: 12
Joined: Fri Sep 02, 2011 12:37 am

Re: Is Love.update reentrant?

Post by MrEricSir »

bartbes wrote:Since nobody seems to have noticed slime's post, I shall redirect you there, he's right.
Another thread can't call love.update, because it doesn't exist there.
I realize that another Lua thread can't call love.update, but I imagine Love itself could do such a thing.

At some point I'm going to have to bust out GDB and see if the call to love.update ended up on the callstack twice somehow.
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is Love.update reentrant?

Post by slime »

MrEricSir wrote:
bartbes wrote:Since nobody seems to have noticed slime's post, I shall redirect you there, he's right.
Another thread can't call love.update, because it doesn't exist there.
I realize that another Lua thread can't call love.update, but I imagine Love itself could do such a thing.

At some point I'm going to have to bust out GDB and see if the call to love.update ended up on the callstack twice somehow.
The C++ side of LÖVE doesn't know about love.update, it's defined by you in Lua and purely called in Lua by love.run (which you can override if you want).
MrEricSir
Prole
Posts: 12
Joined: Fri Sep 02, 2011 12:37 am

Re: Is Love.update reentrant?

Post by MrEricSir »

Okay, I'm starting to think this problem has got to be in my own code then.

Another question though: where's the Lua code for love.run on the repo? I wasn't able to find it.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest