Multi Threading and Corona

Hi,

I am looking for a bit of clarification regarding what I need to worry about when it comes to asynch events / multi threading as a Corona developer. Since there is no notion of synchronization objects in Corona I assume this is not an issue, but still…

Let’s say I have my main lua thread running in a loop filling an array with data and then I have a timed event the wakes up every “X” msecond, checks whether the array contains some data and tries to consume it and finally removes it from the array. In languages which have a notion of threads, I would be required to protect this array from being accessed at the same time by the producer and the consumer of the data inside the array.

So the question is how is this modelled in Corona and what do I need to do as a developer? A tour on this subject would be useful along with an example.

Thanks,
ZigZapps
[import]uid: 110965 topic_id: 25847 reply_id: 325847[/import]

Edit: Double Post [import]uid: 134101 topic_id: 25847 reply_id: 104532[/import]

Corona is single threaded. (Or rather the LUA APIs are; I can’t speak for the inner guts of Corona’s engine)
Lua contains a concept known as Coroutines, but that is not the same as actual multithreading(you need to explicitly declare when to jump from 1 coroutine to another).

Coroutines in more detail are functions that can be resumed later, with all stack-relative data intact. These allow you write code for numerous frames, or executes over X seconds, all within a single function, which is great for animations, or sequential actions (Play Run Animation, Once completed jump), but not so good for providing a smooth framerate while performing heavy operations(like streaming content while playing).

That also means there is no need for synchronization objects or any other threading utilities.

This should hopefully get you started: http://lua-users.org/wiki/CoroutinesTutorial
I can answer more questions if you have them, though I have more knowledge of .NET Coroutines/Enumerators than Lua ones at this point in time. [import]uid: 134101 topic_id: 25847 reply_id: 104531[/import]