Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 1.37 KB

File metadata and controls

66 lines (53 loc) · 1.37 KB

Thread-related instructions

NewASM virtual machine has built-in concurrency, and there are several ways to use this concurrency. Instructions covered in this article:

  1. thread
  2. await
  3. send and recv
  4. async

thread

Used to spawn a thread.

.start
	thread threadIdentifier -> {
		mov tlr, "Hello from thread\n"
		int 0x3
		mov fdx, 1
		sysenter "ios"
		syscall
	}

await

Block an entire program till a specific thread finishes.

await &threadIdentifier

send and recv

Used to manipulate with channels. Channels are data containers used to establish inter-thread communication.

Here's a basic example of using channels:

.data
    ./threads
        ./lol
            cont myChannel: ? chan ; <-- declare a channel
        ./!lol
    ./!threads
.start

    thread testChannel -> {
        recv &threads::lol::myChannel ; <-- this blocks the thread until it receives data, data is stored in tlr
        mov fdx, 1
        sysenter "ios"
        syscall
    }

    send &threads::lol::myChannel, "Data from the channel\n" ; <-- send data
    await &testChannel ; <-- just wait
    sysenter "thread"
    mov tlr, &testChannel
    mov fdx, 1 ; <-- we see thread output
    syscall

async

This is used to create a thread out of a function/procedure.

async &procedureidentifier