(unknown charset) - Paralleling computing with Blackbox and Component Pascal

From: (unknown charset) [at]} <Alexander>
Date: Sat, 8 Apr 2006 02:12:33 +0700

----boundary-LibPST-iamunique-1265491377_-_-
Content-type: text/plain

Hello, Treutwein!

>> In my previous letter I was wrong about one thing. You actually can
>> link BlackBox into a DLL and then use it from C/C++ code (see
>> DevLinker documentation).

TB> hmm, just some thought: There is the option to create a
TB> "dynamic loading" DLL, which is labelled by OMiSys as
TB> "rarely used, present for completeness" which might be
TB> the right thing to use in this case.

>> My guess is that you could call simple functions
>> from C/C++ threads, but anything involving dynamic
>> memory allocation and garbage collection still
>> must be done in only one of those threads.


TB> this is exactly what you would gain from a dynamic
TB> DLL, i.e. one that includes a BlackBox loader:
TB> it would have a separate GC instance for each thread.

  I'm afraid that's not exactly what is said in DevLinker
  documentation. A "dynamic module loader" mentioned there is not
  something that would create a separate instance of GC for every
  thread it loaded into. It's just a module which, when called from
  the main module initialization section, loads other modules
  dynamically. So, this module is just a part of runtime system like
  any other. It can decide which modules to load or even where to load
  from. This is opposed to "static" aka "unextensible" module set. The
  latter set consists of modules which are all known and enumerated at
  link time. So, linker can create a sequence of commands to load and
  initialize those modules.

  I think you've mixed concepts of a dynamic-link library (DLL, windows
  term) and dynamic module loader (BlackBox term). When you link
  BlackBox into a DLL (or EXE) you may or may not use dynamic module
  loader. It doesn't mean you can create two different types of DLLs.

TB> I have no idea, if BlackBox code will be put in
TB> a (shared) code segment or in a thread local
TB> data segment. I know only for sure that "global"
TB> data of a DLL-linked BlackBox module is not global
TB> at all, but thread local. Each thread that attaches
TB> to the DLL gets its own copy of the "global" data.

  Let me reply this way.
  The dynamic memory allocation (procedure NEW and Garbage Collector)
  is performed by module Kernel (source code available at BlackBox\
  System\ Mod\ Kernel.odc).

  When Kernel module is linked into DLL it uses the heap object of a
  parent process to dynamically allocate memory. This heap object is
  obtained from GetProcessHeap() function. The functions used to
  allocate and release memory are HeapAlloc() and HeapFree().

  Here is a recite from Win32 developer's reference (topic on
  "HeapCreate" function):
-- begin recite --
The memory of a private heap object is accessible only to the process
that created it. If a dynamic-link library (DLL) creates a private
heap, the heap is created in the address space of the process that
called the DLL, and it is accessible only to that process.

The system uses memory from the private heap to store heap support
structures, so not all of the specified heap size is available to the
process. For example, if the HeapAlloc function requests 64 kilobytes
(K) from a heap with a maximum size of 64K, the request may fail
because of system overhead.

If the HEAP_NO_SERIALIZE flag is not specified (the simple default),
the heap will serialize access within the calling process.
Serialization ensures mutual exclusion when two or more threads
attempt to simultaneously allocate or free blocks from the same heap.
There is a small performance cost to serialization, but it must be
used whenever multiple threads allocate and free memory from the same
heap.
-- end recite --

  The HEAP_NO_SERIALIZE flag is never specified by the Kernel module
  (and it must never be specified for a heap object obtained from
  GetProcessHeap), so heap memory allocation is thread-safe. What does
  it mean? It means that simultaneous heap allocation and
  deallocation performed by any number of threads will not corrupt
  internal WINDOWS heap-related structures (aka "system overhead" in
  recited text). BUT there is absolutely no guarantee that it will not
  corrupt internal structures of Kernel module itself! (I.e. the chain
  of Cluster objects.)

  Maybe you've mixed concepts of thread and process in your preceding
  text.
  
  My resume: BlackBoxes may live in peace while they are in different
  PROCESSES. However there may be several BlackBoxes in one process
  (look here, Gomez Rubio!) if:
  1) each BlackBox is in separate DLL (to make sure that each has its
  own set of global variables, like "root");
  2) every BlackBox/DLL must be accessed by only a single thread at a
  time.

  AFAIK there is no such thing as "thread-local variable" in Windows
  like there are thread-local variables in Delphi (declared with
  "threadvar" keyword). Global variables declared in a DLL are mapped
  to the address space of a parent PROCESS, so they are
  "process-local". This applies to the "root" global variable in
  module Kernel, which is the first in chain of memory clusters.

  Gomez Rubio, maybe this is what you are looking for? Link modules
  into different DLLs and use those DLLs in parallel threads - one
  thread per DLL?

---===---
 Alexander

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-1265491377_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xyd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iBEZWxwaGkgKGRl
Y2xhcmVkIHdpdGhccGFyDQogICJ0aHJlYWR2YXIiIGtleXdvcmQpLiBHbG9iYWwgdmFyaWFibGVz
IGRlY2xhcmVkIGluIGEgRExMIGFyZSBtYXBwZWRccGFyDQogIHRvIHRoZSBhZGRyZXNzIHNwYWNl
IG9mIGEgcGFyZW50IFBST0NFU1MsIHNvIHRoZXkgYXJlXHBhcg0KICAicHJvY2Vzcy1sb2NhbCIu
IFRoaXMgYXBwbGllcyB0byB0aGUgInJvb3QiIGdsb2JhbCB2YXJpYWJsZSBpblxwYXINCiAgbW9k
dWxlIEtlcm5lbCwgd2hpY2ggaXMgdGhlIGZpcnN0IGluIGNoYWluIG9mIG1lbW9yeSBjbHVzdGVy
cy5ccGFyDQpccGFyDQogIEdvbWV6IFJ1YmlvLCBtYXliZSB0aGlzIGlzIHdoYXQgeW91IGFyZSBs
b29raW5nIGZvcj8gTGluayBtb2R1bGVzXHBhcg0KICBpbnRvIGRpZmZlcmVudCBETExzIGFuZCB1
c2UgdGhvc2UgRExMcyBpbiBwYXJhbGxlbCB0aHJlYWRzIC0gb25lXHBhcg0KICB0aHJlYWQgcGVy
IERMTD9ccGFyDQpccGFyDQotLS09PT09PS0tLVxwYXINCiBBbGV4YW5kZXJccGFyDQpccGFyDQot
LS0gQmxhY2tCb3hccGFyDQotLS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJTQ1JJQkUgdG8g
YmxhY2tib3hAb2Jlcm9uLmNofX0AbW9kdWxlcyB3aA=


----boundary-LibPST-iamunique-1265491377_-_---
Received on Fri Apr 07 2006 - 21:12:33 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:04 UTC