On Mon, Apr 8, 2019 at 11:23:16 UTC+2 Brian Dickens wrote:
> On Mon, Apr 8, 2019 at 3:40 AM <[email protected]> wrote:
>
> > I really cannot believe that it is not possible to compile such
> > a simple interactive program with emcc.  
>
> Believe it.  :-)
>
> The JavaScript hosts like Node.js and browsers weren't designed for 
synchronous I/O.  In a browser you can use Window.prompt() and 
alert()...both of which are too annoying to be practical.  But other than 
that you won't see any I/O or impacts of DOM manipulations.  JavaScript 
programmers have just learned to live with it.
>
> For I/O to process you have to yield to the main loop...which means your C
code can't still be running (on the main thread) when it does.  The only
options for C code that wants to do synchronous I/O while remaining on the
stack are if that code is running on a worker thread, ...

I looked at the worker_threads provided by node.js.
When a worker thread is started it can get some workerData from
the main thread. A worker_thread can also send something back to
the main thread via a parentPort. To receive the message from the
worker_thread the main thread uses something like

  worker.on('message', (msg) => { console.log(msg); });

and then terminates. The message from the worker_thread is then
handled in this callback. I have found also examples where the
worker_thread registers some callback and terminates itself to
receive a message from the main thread. It seems that this works
like anything else in JavaScript: asynchronous

What I am missing is: The worker thread should be able to wait
for a message (without callback and terminating the worker_thread)
and to continue after the message has been received. It is
important that no termination of the thread is necessary and
that the program can continue after the "wait" statement.

A not so elegant solution would be possible, when there is the
possibility to poll, if a message has been sent. In this case
the worker_thread could poll for a message (possibly with some
sleep in between).

I can understand that the main thread works asynchronous and
never waits for something. But for worker_threads this could
be different.

I was thinking to start a worker_thread with the main program
and the main thread would only handle events and sending them
to the worker_thread. To do this the worker_thread must be
able to work synchronous (wait for messages from the main thread).

Is this possible?

Regards,
Thomas Mertes

-- 
Seed7 Homepage:  http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/81abe5a0-70bd-4acb-8747-c59a891ece3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to