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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Concurrent computing step by step in the PureBasic 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 PureBasic programming language

Source code in the purebasic programming language

Global mutex = CreateMutex()

Procedure Printer(*str)
	LockMutex(mutex)
	PrintN( PeekS(*str) )
	UnlockMutex(mutex)
EndProcedure

If OpenConsole()
	LockMutex(mutex)
	thread1 = CreateThread(@Printer(), @"Enjoy")
	thread2 = CreateThread(@Printer(), @"Rosetta")
	thread3 = CreateThread(@Printer(), @"Code")
	UnlockMutex(mutex)
	
	WaitThread(thread1)
	WaitThread(thread2)
	WaitThread(thread3)
	
	Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
	Input()
	
	CloseConsole()
EndIf

FreeMutex(mutex)

  

You may also check:How to resolve the algorithm Range expansion step by step in the ooRexx programming language
You may also check:How to resolve the algorithm XML/XPath step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Quine step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Map range step by step in the Liberty BASIC programming language