How to resolve the algorithm Concurrent computing step by step in the Lua programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Concurrent computing step by step in the Lua programming language

Table of Contents

Problem Statement

Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Concurrent computing step by step in the Lua programming language

Source code in the lua programming language

co = {}
co[1] = coroutine.create( function() print "Enjoy" end )
co[2] = coroutine.create( function() print "Rosetta" end )
co[3] = coroutine.create( function() print "Code" end )

math.randomseed( os.time() )
h = {}
i = 0
repeat
    j = math.random(3)
    if h[j] == nil then
       coroutine.resume( co[j] )
       h[j] = true
       i = i + 1
    end
until i == 3


  

You may also check:How to resolve the algorithm Fixed length records step by step in the COBOL programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the M4 programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the Ring programming language
You may also check:How to resolve the algorithm Write float arrays to a text file step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Textonyms step by step in the Delphi programming language