[Gambas-user] Dining philosophers problem - semaphore , interprocess shared memory concepts using GAMBAS ?
Tobias Boege
taboege at gmail.com
Fri May 24 11:10:27 CEST 2019
On Fri, 24 May 2019, Vinode Singh Ujlain wrote:
> Dining philosophers problem is one that most of us have coded during
> graduation / post graduation courses.
> It amply teaches semaphore , interprocess shared memory concepts.
> Has anyone in this forum attempted this using GAMBAS ? I am keen to learn
> the equivalent of semaphore & shared memory as implemented in GAMBAS
> *Any directions ? *
>
Gambas' parallelism primitive is called Task [1]. It works by forking off
from the main process and communicating with it via a pipe. No data has
to be shared between the processes for this to work and I believe that
this was done to avoid having to introduce the mentioned concepts to the
language.
The naïve solution to Dining philosophers will work in Gambas because
only one philosopher can do something at a time and decides by himself
when he yields control to another philosopher. They can check at leisure
if both forks are on the table and take them both. Single process,
single thread, synchronous execution, very BASIC.
Note that Gambas' event loop still makes it concurrent and you *can* make
deadlocks if you're not careful. But data races are not possible because
code execution is synchronous, so semaphores can be regular integers and
often are just that.
I'm not sure how sharing memory with other, non-Gambas processes is supposed
to make sense. If I was a non-Gambas process and Gambas offered me some
shared variables, I'd politely decline because data in Gambas processes is
boxed in sometimes intricate ways. No, we have no way to share it, except
by serialising and copying it into a stream [2], which is what Tasks do.
Regards,
Tobi
[1] http://gambaswiki.org/wiki/comp/gb/task
[2] http://gambaswiki.org/wiki/lang/datarep
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list