theLink 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - cs - py - rb - jv - cc
Loading...
Searching...
No Matches
HOWTO thread in PLMK

HOWTO configure and use a thread in the Programming-Language-Micro-Kernel (PLMK).

Date
27 dez 2024 - link with C# and Java dokument.
17 dez 2024 - setup of the initial document

INDEX

Thread basics

INDEX

See also
https://en.wikipedia.org/wiki/Thread_(computing)
Thread (computing) from wikipedia

Thread requirements

INDEX

A thread in Programming-Language-Micro-Kernel (PLMK) is very simple:

  1. In PLMK a server-instance always runs in an isolated environment, which means it doesn't matter whether a new process or a separate thread is used.

     !on remote host!                                  !on local host!
    
         server1---------x                     x----------server2
            |            |                     |             |
            |     child-context-1       child-context-2      |
            |            |                     |             |                      server
    parent-context-1-----x                     x-----parent-context-2
            |                                                |
    (MqConfigS::server)                 (example: MqConfigS::server --fork --uds … --file …)
            |                                                |
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            |                                                |
         (--tcp)                                  (--pipe, --uds, --tcp)
            |                                                |
    parent-context-1-----x                     x-----parent-context-2
            |            |                     |             |                      client
            |     child-context-1       child-context-2      |
            |            |                     |             |
            x------------x--------client-------x-------------x
    
                              !on local host!
    
    See also
    libmqmsgque - link - api
    libmqmsgque - service - fac
    libmqmsgque - service - api
  2. From (1) it follows that a thread never accesses a resource that is outside its environment, which means, for example, that a server-instance never accesses an object from another server-instance.
  3. There is a 1:1 relationship between a server-instance and a thread.
  4. All data types of a server-instance are in a structure, e.g. MkRuntimeC, which is always defined as thread-local-storage.
  5. Every object is firmly linked to its server-instance via MkObjectS::objRt.
  6. Transferring an object-pointer from one server-instance to another server-instance is a design flaw.

Thread startup

INDEX

A thread in Programming-Language-Micro-Kernel (PLMK) is created via pIoStartServer, whereby all types of instances (pipe, spawn, fork, thread, etc.) can be created in the function.

Thread storage

INDEX - MkKernel_Storage_C_API - MkRuntimeC_C_API

The primary memory for a multi-threaded application is the thread-local-storage.

Thread pool

INDEX

The initial implementation of the Programming-Language-Micro-Kernel (PLMK) thread was without thread-pool.

The biggest difference between a single pthread-thread and an already used thread-pool-thread is:

The biggest difference between a single-threaded application (process) and a multi-threaded application is:

  • The memory of a single-threaded application is cleaned up by the operating system at the end of the process.
  • The memory of a multi-threaded application must be cleaned up by the programmer at the end of the thread.

The biggest difference between a multi-thread-once and a multi-thread-pool application is:

  • When a thread is used once, the thread-local-storage memory is released by the operating system but not the pointer to the heap contained therein.
    • The memory must therefore be cleaned up.
  • When a thread is used multiple times, the thread-local-storage memory is not released and is reused.
    • However, the memory must be initialized again.
See also
C# Thread-Pool
JAVA Thread-Pool

Weak or Strong reference

INDEX

A weak reference is a reference that is controlled by Target-Programming-Language (TPL), and a strong reference is a reference that is controlled by Programming-Language-Micro-Kernel (PLMK).

The difference lies in the lifetime of the object:

With the switch to thread pool in C# and Java, the reference-technology was also switched from strong to weak because there is always a memory problem in a multi-threaded application and a language like C# and Java is better equipped with the sophisticated garbage-collection than Programming-Language-Micro-Kernel (PLMK).

See also
C# references
JAVA references