- Re[2]: - Paralleling computing with Blackbox and Component Pascal

From: [at]} <Alexander>
Date: Wed, 29 Mar 2006 02:36:03 +0700

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

Hello, Virgilio!

GRV> Many thanks for your message. After your response I am wandering
GRV> if it would be possible to, let's say, write some code in C/C++
GRV> to parallelize the work and call my previous BlackBox routines
GRV> from the new C/C++ code. :D

  Always a pleasure to be helpful. : )
  But it turns out that I spoke too soon: it IS possible to create
  threads in BlackBox. In fact if you look at the source of module
  Kernel (as I did just now), you'll see that it uses
  KERNEL32.CreateThread (which maps to the WinAPI CreateThread, of
  course) to create a keyboard watcher thread. That is how BlackBox
  knows if you press Ctrl+Break. The code function for the thread is
  located there too, called KeyboardWatcher.

  All this means that you CAN use threads in BlackBox as long as you
  know the appropriate API functions.

  There are also some bad news again. As far as I know the memory
  management is NOT thread-safe in BlackBox. All that pretty stuff
  with dynamic memory allocation and garbage collection should be
  avoided within all threads except the main one.
  I found no more references in BlackBox sources to the CreateThread
  function except when it is used to setup KeyboardWatcher. If you
  look at the Kernel.KeyboardWatcher procedure, you'll see that it
  does not create any objects or arrays, it only uses local
  stack-based variables. And when watcher thread needs to communicate
  to the main thread (to set break flag) it suspends the latter!

  As to calling BlackBox code from C/C++ code - there is no
  straightforward way to do this. I mean you cannot import a module
  with a header file and then use calls like
  BlackboxModule.ExecuteFunction(params);
  It won't work. You'll need to develop some communication interface
  (windows messages, memory mapped files, files, pipes, TCP/IP,
  mailslots, OLE automation or whatever you can think of) and then use
  that interface to pass parameters to your code in BlackBox and get
  outcome it will produce.
  
  If your Component Pascal code uses dynamic memory allocation
  (arrays, strings, objects) you'll have to run separate BlackBox
  instances for every line of parallel work. If your functions use
  only local variables and neither of them is an array, then you can
  use them in threads. You'll meet some troubles transferring outcome
  of execution into the main thread, but that's solvable.
  
  Another way is to redesign your code to make it capable of executing
  its work in small chunks one-by-one - and then you could use
  Services.Action as described in help files.

  Resume:
  1. You may write thread code entirely in C/C++, put it in a DLL and
  then use the DLL in BlackBox. The DLL cannot call any of the
  BlackBox's procedures.
  2. You may write thread code in BlackBox keeping in mind one general
  limitation: thread must manage its own memory (i.e. not to use NEW).
  All other issues of concurrent multitasking also must be considered.
  3. You may use cooperative multitasking as supported in module
  Services.
  4. You may redesign BlackBox memory management to make it
  thread-safe. Hmm... that sounds like an interesting task.
  
  PS: if you want to pass blocks of memory to or from thread, you
  should use windows' GlobalAlloc/GlobalFree functions to allocate and
  release memory. But that memory, of course, falls outside the
  garbage collector's scope and you'll have to manage it yourself.
  ... which brings us back to good old pre-Oberon days : )

  ("... which brings us, once again, to the ugrent realization of just
  how much there is still left to own" (c) Mony Python's the Meaning
  of Life)

---===---
 Alexander

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



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

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhlbGxvLCBWaXJnaWxpbyFccGFyDQpccGFyDQpH
UlY+IE1hbnkgdGhhbmtzIGZvciB5b3VyIG1lc3NhZ2UuIEFmdGVyIHlvdXIgcmVzcG9uc2UgSSBh
bSB3YW5kZXJpbmdccGFyDQpHUlY+IGlmIGl0IHdvdWxkIGJlIHBvc3NpYmxlIHRvLCBsZXQncyBz
YXksIHdya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94QG9iZXJvbi5jaH19ACBB
cHIgMjAwNiA

----boundary-LibPST-iamunique-261856647_-_---
Received on Tue Mar 28 2006 - 20:36:03 UTC

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