« blib/lib/SPVM/Document/Language/SyntaxParsing.pm
↑ Summary
blib/lib/SPVM/Document/Language/Tokenization.pm »
| 1 | =head1 Name | ||
| 2 | |||
| 3 | SPVM::Document::Language::System - System Setting in the SPVM Language | ||
| 4 | |||
| 5 | =head1 Description | ||
| 6 | |||
| 7 | This document describes system setting in the SPVM language. | ||
| 8 | |||
| 9 | =head1 System Setting | ||
| 10 | |||
| 11 | =head2 Standard Streams | ||
| 12 | |||
| 13 | SPVM opens own standard input, standard output, and standard error for a runtime just after a runtime is build. | ||
| 14 | |||
| 15 | Their open modes are set to L<binary mode|https://learn.microsoft.com/en-us/cpp/c-runtime-library/text-and-binary-mode-file-i-o?view=msvc-170> in Windows. | ||
| 16 | |||
| 17 | The L<print operator|SPVM::Document::Language::Operators/"print Operator"> outputs to this SPVM's standard output. | ||
| 18 | |||
| 19 | The L<say operator|SPVM::Document::Language::Operators/"say Operator"> outputs to this SPVM's standard output. | ||
| 20 | |||
| 21 | The L<warn operator|SPVM::Document::Language::Operators/"warn Operator"> outputs to this SPVM's standard error. | ||
| 22 | |||
| 23 | =head2 Thread Safety | ||
| 24 | |||
| 25 | The SPVM language has some thread-safe features. | ||
| 26 | |||
| 27 | =head3 Runtime Stack | ||
| 28 | |||
| 29 | When a new thread, such as an L<OS native thread|SPVM::Thread>, a coroutine such as a L<goroutine|SPVM::Go> is created, a new L<runtime stack|SPVM::Document::NativeClass/"Runtime Stack"> should be created for the new thread. | ||
| 30 | |||
| 31 | SPVM_VALUE* new_stack = env->new_stack(env); | ||
| 32 | |||
| 33 | 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. | ||
| 34 | |||
| 35 | When the new thread finished, the new runtime stack must be released. | ||
| 36 | |||
| 37 | env->free_stack(env, new_stack); | ||
| 38 | |||
| 39 | Currently, user data cannot be got and set in a runtime stack. | ||
| 40 | |||
| 41 | If thread-specific user data is needed, the thread ID is got by L<Thread#get_id|SPVM::Thread#get_id> method and this thread ID can be a key of a L<hash|SPVM::Hash> for thread-specific user data. In this case, L<Hash|SPVM::Hash> class is not thread safe, a lock using a L<mutex|SPVM::Sync::Mutex> is needed. | ||
| 42 | |||
| 43 | =head2 Atomic Operations | ||
| 44 | |||
| 45 | This section describe atomic operations. | ||
| 46 | |||
| 47 | Generally speaking, when using L<OS native threads|SPVM::Thread> with SPVM, the following atomic operations can result in severe performance degradation. | ||
| 48 | |||
| 49 | Therefore, the advice is to minimize object creations and object assignments in newly created L<OS native threads|SPVM::Thread>. | ||
| 50 | |||
| 51 | Coroutine threads such as L<goroutines|SPVM::Go> don't have to worry about things like this because these are synchronized. | ||
| 52 | |||
| 53 | =head3 Updating Memory Blocks Count | ||
| 54 | |||
| 55 | Updating the count of allocated memory blocks is an atomic operation and thread safe. It is protected by a mutex. | ||
| 56 | |||
| 57 | The count of all allocated memory blocks in a runtime is managed and is got by L<get_memory_blocks_count|SPVM::Document::NativeAPI/"get_memory_blocks_count"> native API. | ||
| 58 | |||
| 59 | =head3 Updating Runtime Cache | ||
| 60 | |||
| 61 | Updating a runtime cache data is an atomic operation and thread safe. It is protected by a mutex. | ||
| 62 | |||
| 63 | =head3 Compilation | ||
| 64 | |||
| 65 | A compilation is an atomic operation and thread safe. It is protected by a mutex. | ||
| 66 | |||
| 67 | =head3 Updating Reference Count | ||
| 68 | |||
| 69 | Updating the reference count of an object an atomic operation and thread safe. It is protected by a mutex. | ||
| 70 | |||
| 71 | =head1 See Also | ||
| 72 | |||
| 73 | =over 2 | ||
| 74 | |||
| 75 | =item * L<SPVM::Document::Language::Operators> | ||
| 76 | |||
| 77 | =item * L<SPVM::Document::Language> | ||
| 78 | |||
| 79 | =item * L<SPVM::Document> | ||
| 80 | |||
| 81 | =back | ||
| 82 | |||
| 83 | =head1 Copyright & License | ||
| 84 | |||
| 85 | Copyright (c) 2023 Yuki Kimoto | ||
| 86 | |||
| 87 | MIT License |