Multithreading?

One question - will apps in Corona be executed in more than a single thread?

If the answer is yes, are there any SDK-provided functions to set locks on objects and the like (such as semaphores?)?

Thanks to anyone who might help me here! [import]uid: 139365 topic_id: 30227 reply_id: 330227[/import]

Stuff you write in Lua will always be on the same thread.

Stuff we write in Corona or the OS vendor writes in their frameworks may or may not occur on different threads. These are implementation details that you should not need to worry about.
[import]uid: 7563 topic_id: 30227 reply_id: 121080[/import]

coroutines? [import]uid: 160496 topic_id: 30227 reply_id: 121085[/import]

Thanks for the reply ewing! Just a little clarification: does this include the handling of events and timers? For example:

local object = {}  
  
function object:touch(event)  
 if event.phase == "moved" then  
 doThis()  
 elseif event.phase == "ended" then  
 doThat()  
 end  
end  
  
object:addEventListener("touch", object)  
timer.performWithDelay(10, doThis, 0)  

Is doThis() in the touch event guaranteed to return before doThat() will be called and there will never be two instances of doThis() (invoked by the touch event and the timer)?

@mike470: what do you mean with coroutines? [import]uid: 139365 topic_id: 30227 reply_id: 121129[/import]

Yes. Your doThis() must finish before we can invoke another event since this is all on the same thread.

Coroutines can be thought as co-operative threads/multitasking. You can create your own co-routines in Lua. From an operating system standpoint, they will be on the same thread. And coroutines are not preemptive. You manually yield and resume coroutines to transfer control. But this can help let you write concurrent-like code without all the headaches of syncing and locking.

[import]uid: 7563 topic_id: 30227 reply_id: 121196[/import]

Thanks @ewing, do you have any good links for learning about coroutines? [import]uid: 8271 topic_id: 30227 reply_id: 121216[/import]

I would recommend Programming in Lua. I’ve been planning to write one too, but haven’t had enough spare time.

[import]uid: 7563 topic_id: 30227 reply_id: 121378[/import]

Stuff you write in Lua will always be on the same thread.

Stuff we write in Corona or the OS vendor writes in their frameworks may or may not occur on different threads. These are implementation details that you should not need to worry about.
[import]uid: 7563 topic_id: 30227 reply_id: 121080[/import]

coroutines? [import]uid: 160496 topic_id: 30227 reply_id: 121085[/import]

Thanks for the reply ewing! Just a little clarification: does this include the handling of events and timers? For example:

local object = {}  
  
function object:touch(event)  
 if event.phase == "moved" then  
 doThis()  
 elseif event.phase == "ended" then  
 doThat()  
 end  
end  
  
object:addEventListener("touch", object)  
timer.performWithDelay(10, doThis, 0)  

Is doThis() in the touch event guaranteed to return before doThat() will be called and there will never be two instances of doThis() (invoked by the touch event and the timer)?

@mike470: what do you mean with coroutines? [import]uid: 139365 topic_id: 30227 reply_id: 121129[/import]

Yes. Your doThis() must finish before we can invoke another event since this is all on the same thread.

Coroutines can be thought as co-operative threads/multitasking. You can create your own co-routines in Lua. From an operating system standpoint, they will be on the same thread. And coroutines are not preemptive. You manually yield and resume coroutines to transfer control. But this can help let you write concurrent-like code without all the headaches of syncing and locking.

[import]uid: 7563 topic_id: 30227 reply_id: 121196[/import]

Thanks @ewing, do you have any good links for learning about coroutines? [import]uid: 8271 topic_id: 30227 reply_id: 121216[/import]

I would recommend Programming in Lua. I’ve been planning to write one too, but haven’t had enough spare time.

[import]uid: 7563 topic_id: 30227 reply_id: 121378[/import]