<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<body bgcolor="#ffffff" text="#000000">
Igor Stasenko wrote:
2008/9/14 Esteban Lorenzano <a class="moz-txt-link-rfc2396E" href="mailto:email@example.com"><firstname.lastname@example.org></a>:
I need some help/advice for a plugin I'm writing.
I'm already downloaded VMMaker and managed to compile a new VM in OS/X, and
I already write and compile and test a simple plugin (and I have to say the
process is very simple, and all my problems were because I never used Xcode
before), but now, with the plugin running, comes the "optimization" phase,
and there I have many doubts:
1) An external plugin blocks the VM when primitive is called? if so, how do
I manage to avoid this?
No way. Primitive implements the behavior of your method. You can't
run interpreter before it will return.
Of course you can use pthreads: create own native thread and pass all
you need to this thread using own synchronization scheme. Then you can
avoid blocking. But this comes handy if your task is parallelisable.
Some are simply can't be parallelised.
To elaborate on Igor's response, Squeak has a way to register a
Semaphore object with the VM. If you want native code to work
asynchronously in another thread, you would write a primitive that
would queue the task up for the worker thread, then returns immediately
(so that bytecode interpretation can resume). Then, when your worker
thread is finished, it signals the semaphore. Typically, you will have
a Squeak Process looping and blocking on that semaphore; when the
semaphore is signalled you know that there is data available to read
back from the plugin (you would use a different primitive to read the
As Igor says, you will often just want to wait for the primitive to
return. A good rule-of-thumb is to ask yourself, if your whole program
was written in C, would this be a place that you would use a separate
worker thread. If not, then you probably don't want to do it for a
Squeak primitive either.<br>