On 5 January 2011 21:40, Eliot Miranda <eliot.mira...@gmail.com> wrote:
>
>
> On Wed, Jan 5, 2011 at 11:58 AM, Igor Stasenko <siguc...@gmail.com> wrote:
>>
>> On 5 January 2011 20:07, Eliot Miranda <eliot.mira...@gmail.com> wrote:
>> >
>> >
>> > On Wed, Jan 5, 2011 at 10:36 AM, Igor Stasenko <siguc...@gmail.com>
>> > wrote:
>> >>
>> >> I think any interoperability should have a reasonable limitations.
>> >> Otherwise, there is no way how to guarantee the system stability.
>> >>
>> >> Squeak and Cog virtual machines can't run multiple native threads
>> >> interpreting smalltalk code, which means that
>> >> any callback(s) will be forced to be handled in single (VM) thread.
>> >
>> > No.  One can arrange to shae the VM between native threads just like
>> > Python,
>> > which is what I've done in my prototype.
>> >
>>
>> i didn't said it can't, i just don't see a reason for doing that. Too
>> much for it.
>
> What do you mean "too much for it"?  It costs too much?

yes. too much for just 'callbacks'.
I wouldn't bother about costs if it would be something bigger.. but if
it just for callbacks, then its too much as to me.
Don't take me wrong, it would be good to have: a thread-aware VM is
step forward anyways :)

>
>>
>> >>
>> >> Apparently callbacks from foreign threads require a special checks to
>> >> be added to detect it and then serialize the call to vm thread.
>> >
>> > No.  One can arrange for the current thread to cede ownership to the
>> > foreign
>> > thread and allow it to run.  With a two-evel scheduler one can still
>> > arrange
>> > to preserve Smalltalk process priorities and scheduling semantics.
>> >  Essentially one assigns a priority to foreign callbacks and they get to
>> > run
>> > as soon as their priority is high enough to displace the priority of the
>> > current process (in whatever thread it may be).
>> > The scheme you're describing is one I implemented in VisualWorks and it
>> > is
>> > slow and clumsy.  The scheme I'm now using is due to David Simmons and
>> > by
>> > comparison is lightweight and fast.  But neither are simple.
>> >
>>
>> Sharing VM among multiple threads.. Okay.. but this is same.
>> It doesn't eliminates a need of synchronizing with thread which
>> currently 'owns' VM to obtain a control,
>> which means you can't start handling callback immediately, that's why
>> i told that it kills an idea of using multithreading.
>
> That doesn't follow.  he fact you can't release the VM immediately doesn't
> mean it can't happen very quickly, certainly quickly enough.  Nothing
> happens instantaneously in a computer.  Computations take time. Thread
> switches take time.  But computers are fast.  So I don't see that the idea
> of using multithreading is killed at all.
>

Can VM handle two callbacks in parallel? No? Case closed :)
I just don't like that in certain scenarios VM will serve as a
lobotomizer for any external libraries,
which invented a highly sophisticated ways to do multiple things at one time.
I can hear a future woes and whines about 'why it sooo fast in X , but
soo sloww smalltalk'  :)

And of course, for manycore era (which is yet-yet not happen), we have
to propose something completely different,
because given solution simply won't scale.
But that of course affects many other systems and languages not just
our  beloved one :)

>>
>> Again, i hope you realizing that there is a lot of situations, where
>> this won't go.
>> Suppose that i using some library which using a thread-local storage.
>> How i could guarantee that all calls to this library will be made in
>> same thread,
>> in situation, when VM could run interpreter in any random thread,
>> resulted because of need to handle callback
>> from other library, not related to one that used by code related to my
>> library?
>
> Because my system allows one to bind a process to a specific thread so that
> you can guarantee which thread a computation will run in by reserving a
> process for that computation and binding it to the relevant thread.  The
> process scheduler (remember this is now a two-level scheduler) takes care of
> switching threads when one switches processes.
>

That's not really solves the problem. Nothing prevents me from using
same primitive(s) in different
processes, which could lead to fatal error(s). Of course it is better
than nothing..
But this will mean introducing some discipline into smalltalk code
(and Debugger and Process etc etc) which is an added price, once you
putting threaded callbacks into the cart, regardless whether you
currently using them in your code or not.

I wouldn't bother, but then again, seeing in what appalling state
Squeak's own thread safety and scheduling is,
i'd say it will take a loong road before we get to something stable
out of it :)


>>
>> I don't see how it can be made 'automagically' without introducing an
>> additional discipline in code, and without any
>> notion of native threads at language side, where developer could
>> enforce some rules, known by him. Otherwise an interoperability scheme
>> which you introducing is mine field.
>
> If one has to interoperate with code that has threading constraints (such as
> your example above) then one needs to code to those constraints.  To be able
> to code to those constraints there has to be some relevant mechanism.  That
> relevant mechanism is implementable (I have implemented it).  But I don't
> see what your argument is.  The current non-threaded system doesn't provide
> any way of interacting with foreign threads directly, right?  So interacting
> requires programming.  Introducing threading into the VM makes things
> easier, not more difficult, no?
>

It opens certain perspectives. Of course. About making things easier..
One good property of the concurrency mine-field,
that its not magically disappears once you start using some pre-made
uber-cool library. You either always following rules and write
a concurrent code _everywhere_, or not.. and have an unwanted consequences.
And any futile attempts to mask the complexity leads to even more
frustration in the end :)

>> Also, now  you must check every single primitive which currently used
>> by VM is thread safe, i.e.
>> it can be invoked from any 'random' thread without leading to unwanted
>> effect(s). Which is a good thing (oh and i did that in Hydra btw).
>
> Why?
>

you asking why its good? because if you know if prim (or perhaps
plugin) is thread safe, then you can use it in any thread :)

>>
>> I know very well that some OS(es) and some libraries don't like when
>> you using their functions either
>> from non-main process thread, or from multiple threads. (Btw, Johm
>> told scary story about GUI and multithreading on Macs multiple times
>> ;) )
>>
>> So, before introducing such kind of sharing , you should take care
>> about every single
>> primitive which using OS-specific function(s) or using some external
>> library, that it is safe to make a calls
>> from random thread.
>
> You certainly need to be able to control threading, yes.  But you're being a
> bit of a Cassandra.    Most primitives are the VM's own and they work fine
> whatever thread they're in.  GUI activities can be restricted to the GUI
> thread.  FFI calls can be marked as threaded or non-threaded.  Porcesses can
> be bound to threads or free to run on any thread.  So there's lots of
> control.   The system doesn't collapse into chaos as soon as one introduces
> a thread.

It doesn't collapse. Not at all. But it certainly becomes more brittle.
Once (or if) you release the code, i will gladly show you some
exploits, and of course would be happy if they won't break anything :)

>>
>> So, the question remains open: is it worth spending so much efforts
>> for such small outcome? :)
>
> Small outcome?  The ability to interact with multi-threaded libraries is a
> small outcome?  The ability to perform non-blocking calls is a small
> outcome?  We see things differently :)

I meant just callbacks. For threaded calls i think i would just
introduce a native threads control into language
and let developer to instruct VM, from which thread do a certain call(s).
That's much cheaper because it doesn't requires big changes from VM side.

> best
> Eliot


-- 
Best regards,
Igor Stasenko AKA sig.

Reply via email to