Lua-RTOS-ESP32 icon indicating copy to clipboard operation
Lua-RTOS-ESP32 copied to clipboard

Enhancement - CSPlike channels

Open Bazmundi opened this issue 6 years ago • 6 comments

Since Lua-RTOS has tasks it would make sense to look at CSP like channels.

Starting postion might be LuaCSP perhaps. Or perhaps go like lua-channels.

Bazmundi avatar Oct 05 '18 12:10 Bazmundi

@Bazmundi,

Lua RTOS is a multi-thread Lua environment, which means that Lua scripts can run on multiple threads sharing the global state, so a global variable can be shared by multiple threads, and special Lua libraries are provided to protect concurrent access and synchronise threads:

This is slightly different from other Lua concurrent approaches based on processes, in which each process runs a single-threaded Lua instance, each one with its own Lua state. In this approach, a communication mechanism between Lua instances is required to interchange data, because processes are isolated.

As far I can see, I'm not sure about the benefits of introducing a channel communication mechanism in Lua RTOS to share data between threads, because introduces an unnecessary overhead.

jolivepetrus avatar Oct 07 '18 22:10 jolivepetrus

go lang site suggests:

In general use channels when Goroutines need to communicate with each other and mutexes when only one Goroutine should access the critical section of code.

So, it depends on use cases. Events don't fit this use case in the absence of a payload. A payload on events might be of limited use. If you are suggesting global variables with an event and mutexes to act as a "channel" mechanism then you have your argument for channels.

On Mon, Oct 8, 2018 at 9:08 AM Jaume Olivé Petrus [email protected] wrote:

@Bazmundi https://github.com/Bazmundi,

Lua RTOS is a multi-thread Lua environment, which means that Lua scripts can run on multiple threads sharing the global state, so a global variable can be shared by multiple threads, and special Lua libraries are provided to protect concurrent access and synchronise threads:

This is slightly different from other Lua concurrent approaches based on processes, in which each process runs a single-threaded Lua instance, each one with its own Lua state. In this approach, a communication mechanism between Lua instances is required to interchange data, because processes are isolated.

As far I can see, I'm not sure about the benefits of introducing a channel communication mechanism in Lua RTOS to share data between threads, because introduces a unnecessary overhead.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/whitecatboard/Lua-RTOS-ESP32/issues/199#issuecomment-427693220, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsMK2K3RTBKMi06TKv5u5RJGc_iTJ6Gks5uioJWgaJpZM4XKJNv .

Bazmundi avatar Oct 08 '18 07:10 Bazmundi

A more detailed discussion is at: http://www.flounder.com/no_synchronization.htm

On Mon, Oct 8, 2018 at 6:14 PM Asterion Daedalus < [email protected]> wrote:

go lang site suggests:

In general use channels when Goroutines need to communicate with each other and mutexes when only one Goroutine should access the critical section of code.

So, it depends on use cases. Events don't fit this use case in the absence of a payload. A payload on events might be of limited use. If you are suggesting global variables with an event and mutexes to act as a "channel" mechanism then you have your argument for channels.

On Mon, Oct 8, 2018 at 9:08 AM Jaume Olivé Petrus < [email protected]> wrote:

@Bazmundi https://github.com/Bazmundi,

Lua RTOS is a multi-thread Lua environment, which means that Lua scripts can run on multiple threads sharing the global state, so a global variable can be shared by multiple threads, and special Lua libraries are provided to protect concurrent access and synchronise threads:

This is slightly different from other Lua concurrent approaches based on processes, in which each process runs a single-threaded Lua instance, each one with its own Lua state. In this approach, a communication mechanism between Lua instances is required to interchange data, because processes are isolated.

As far I can see, I'm not sure about the benefits of introducing a channel communication mechanism in Lua RTOS to share data between threads, because introduces a unnecessary overhead.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/whitecatboard/Lua-RTOS-ESP32/issues/199#issuecomment-427693220, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsMK2K3RTBKMi06TKv5u5RJGc_iTJ6Gks5uioJWgaJpZM4XKJNv .

Bazmundi avatar Oct 08 '18 07:10 Bazmundi

If it helps, even Kotlin has gone for channels.

Bazmundi avatar Jul 05 '19 13:07 Bazmundi

Events can be used to synchronize two tasks. For example between producer and consumer for the management of a buffer but I cannot use them. Have any of you tried them?

rosarioculmone avatar Nov 04 '20 15:11 rosarioculmone

Events are not channels.

On Thu, 5 Nov. 2020, 02:25 rosarioculmone, [email protected] wrote:

Events can be used to synchronize two tasks. For example between producer and consumer for the management of a buffer but I cannot use them. Have any of you tried them?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/whitecatboard/Lua-RTOS-ESP32/issues/199#issuecomment-721815592, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANQYK34FGQAM7THJTFM3CTSOF2QVANCNFSM4FZISNXQ .

Bazmundi avatar Nov 05 '20 22:11 Bazmundi