[Vm-dev] help on creating plugin
schwa at fastmail.us
Sat Sep 13 21:42:25 UTC 2008
Igor Stasenko wrote:
> 2008/9/14 Esteban Lorenzano <estebanlm at gmail.com>:
>> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Vm-dev