The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Document::Language::System - System Setting in the SPVM Language

Description

This document describes system setting in the SPVM language.

System Setting

Standard Streams

SPVM opens own standard input, standard output, and standard error for a runtime just after a runtime is build.

Their open modes are set to the binary mode in Windows.

The print operator outputs to this SPVM's standard output.

The say operator outputs to this SPVM's standard output.

The warn operator outputs to this SPVM's standard error.

Thread Safety

The SPVM language has some thread-safe features.

Runtime Stack

When a new thread, such as an OS native thread, a coroutine such as a goroutine is created, a new runtime stack should be created for the new thread.

  SPVM_VALUE* new_stack = env->new_stack(env);

This runtime stack has thread-specific data, such as the value of the exception variable, as well as method-specific data, such as arguments and a return value.

When the new thread finished, the new runtime stack must be released.

  env->free_stack(env, new_stack);

Currently, user data cannot be got and set in a runtime stack.

If thread-specific user data is needed, the thread ID is got by the Thread#get_id method and this thread ID can be a key of a hash for thread-specific user data. In this case, the Hash class is not thread safe, a lock using a mutex is needed.

Atomic Operations

This section describe atomic operations.

Generally speaking, when using OS native threads with SPVM, the following atomic operations can result in severe performance degradation.

Therefore, the advice is to minimize object creations and object assignments in newly created OS native threads.

Coroutine threads such as goroutines don't have to worry about things like this because these are synchronized.

Updating Memory Blocks Count

Updating the count of allocated memory blocks is an atomic operation and thread safe. It is protected by a mutex.

The count of all allocated memory blocks in a runtime is managed and is got by the get_memory_blocks_count native API.

Updating Runtime Cache

Updating a runtime cache data is an atomic operation and thread safe. It is protected by a mutex.

Compilation

A compilation is an atomic operation and thread safe. It is protected by a mutex.

Updating Reference Count

Updating the reference count of an object an atomic operation and thread safe. It is protected by a mutex.

See Also

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License