builtin and Mozart synchronization

Vladimir Zykov zykov at online.kharkov.ua
Fri Jan 17 16:57:53 CET 2003


Hello Oz users,

I have a question about how to synchronize a builtin and a Mozart
part. I have a simple builtin that generates a sequence of numbers
and sends them to a port. In a Mozart functor I pick up those numbers
and output to the screen.

----sample.cpp code----
#include <windows.h>
#include <mozart.h>

HANDLE testThread;

DWORD WINAPI ThreadFunc(LPVOID param) {
  OZ_Term port = (OZ_Term) param;
  Sleep(1000);
  for (int i = 0; i < 1000; i++) {
    OZ_warning("int = %d", i);
    OZ_send(port, OZ_int(i));
    Sleep(500);
  }
  return 0;
}
//---------------------------------------------------------------------------
OZ_BI_define(start, 1, 0) {
  OZ_declareDetTerm(0, port);
  DWORD id;
  testThread = CreateThread(NULL, 0, ThreadFunc,
                            (void *) port, 0, &id);
  if (testThread != NULL) {
    OZ_warning("CreateThread succeeded.");
  }
  return PROCEED;
}
OZ_BI_end
//---------------------------------------------------------------------------
OZ_BI_define(stop, 0, 0) {
  TerminateThread(testThread, 0);
  return PROCEED;
}
OZ_BI_end
//---------------------------------------------------------------------------
OZ_C_proc_interface *oz_init_module() {
  static OZ_C_proc_interface table[] = {
    {"start", 1, 0, start},
    {"stop", 0, 0, stop},
    {0, 0, 0, 0}
  };
  return table;
}
//---------------------------------------------------------------------------

This can be compiled with the following commands (I have cygwin).

oztool c++ -c sample.cpp
oztool ld sample.o -o sample.so-win32-i486

If I try the following Mozart code then I got all the numbers
generated by the builtin presented above.

functor
import
%   System(show:Show)
   Browser(browse:Browse)
   Sample(start:SampleStart
          stop:SampleStop) at 'sample.so{native}'
   Application
define
   S P = {NewPort S}
   {SampleStart P}

   thread
      for X in S
      do
%         {Show 'in Mozart'#X}
         {Browse 'in Mozart'#X}
      end   
   end

   {Delay 10000}
   
   {SampleStop}
   {Delay 5000}
   
   {Application.exit 0}
end

The problem is that I got all those numbers at the end of the run i.e.
when a thread in the builtin terminates, which is not the case if I
use System.show. With System.show the mozart part receives those
number as soon as they are sent to a port by builtin. Do anybody have
an idea how to make Browser.browse working in a similar fashion?

Any help will be appreciated.

Thanks.

-- 
Best regards,
 Vladimir                          mailto:zykov at online.kharkov.ua

-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
Please send bug reports to bugs at mozart-oz.org.





More information about the mozart-users mailing list