Re: [Newbies] BlockClosurefork problem

2007-02-20 Thread Michael Davies

George,

You'll find that writing to the Transcript always slows things down. I
assume it's the time for writing to the Transcript that also causes
the second process to start after a different interval each time.
Writing the results into an OrderedCollection will be much faster, and
more predictable:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2'. (Delay forMilliseconds: 1) wait]] fork.
[10 timesRepeat: [a addLast: '1'. (Delay forMilliseconds: 1) wait]] fork.
a inspect.

consistently gives 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1.

Without the delay:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2']] fork.
[10 timesRepeat: [a addLast: '1']] fork.
a inspect.

consistently gives 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1.

Cheers,
Michael
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] Process Scheduling (was Re: BlockClosurefork problem)

2007-02-20 Thread Bert Freudenberg

On Feb 20, 2007, at 11:05 , Michael Davies wrote:


George,

You'll find that writing to the Transcript always slows things down. I
assume it's the time for writing to the Transcript that also causes
the second process to start after a different interval each time.


Besides, it interferes with processes because it has a Mutex  
nowadays. Which is good, but it distorts what you would observe  
without the Transcript involved.



Writing the results into an OrderedCollection will be much faster, and
more predictable:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2'. (Delay forMilliseconds: 1) wait]]  
fork.
[10 timesRepeat: [a addLast: '1'. (Delay forMilliseconds: 1) wait]]  
fork.

a inspect.

consistently gives 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1.


This is because waiting on Delay (or, rather on the Semaphore inside)  
causes the current process to block, and the next process on the same  
priority to run. The same could be achieved by Processor yield  
instead of waiting on the Delay. This is cooperative. Or, you could  
have a higher-priority scheduler that time-slices the lower-priority  
ones by suspending them in turn, which does not need cooperation.



Without the delay:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2']] fork.
[10 timesRepeat: [a addLast: '1']] fork.
a inspect.

consistently gives 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1.


These processes are too short-lived to ever get interrupted by a  
higher priority process. So the first one runs to completion, then  
the second one. Try this instead:


a := String new writeStream.
p1 := [[a nextPut: $1] repeat] forkAt: Processor userBackgroundPriority.
p2 := [[a nextPut: $2] repeat] forkAt: Processor userBackgroundPriority.
10 timesRepeat: [(Delay forMilliseconds: 1) wait].
p1 terminate.
p2 terminate.
a contents

This puts the two processes into a lower priority than the UI  
process. We then stop the UI process 10 times for one millisecond -  
this is our scheduler. Each time, the next lower-priority process is  
given time to run - that is the default scheduling behavior. The  
result are nicely alternating runs of ones and twos as you would  
expect: '112221222...'


- Bert -


___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] Creating custom events in a domain.

2007-02-20 Thread Mispunt

Hi Squeakers,

I am working an a project where we have a domain. this domain should
not know the classes outside the world, so to communicate the domain
should fire an event where the classes outside the domain could react
to.
How could this be done? I didn't find anything about it in the wiki..

Kind regards,

Mispunt
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Creating custom events in a domain.

2007-02-20 Thread Giovanni Corriga
Il giorno mar, 20/02/2007 alle 12.43 +0100, Mispunt ha scritto:
 Hi Squeakers,
 
 I am working an a project where we have a domain. this domain should
 not know the classes outside the world, so to communicate the domain
 should fire an event where the classes outside the domain could react
 to.
 How could this be done? I didn't find anything about it in the wiki..

Hi Mispunt,

you may try using the Announcements framework. Lukas Renggli recently
blogged about it at http://www.lukas-renggli.ch/blog/decoupling

Ciao,

Giovanni

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] BlockClosurefork problem

2007-02-20 Thread George Herolyants
Thanks for this answer, Ron. But actually I'm not confused with order in 
wich '1' and '2' presents in result line. I can't understand why in some 
cases this code results ten '1' and ten '2' and in some cases it results 
ten '2' and only nine '1'?

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] BlockClosurefork problem

2007-02-20 Thread George Herolyants

Thanks, Michael!
Now I know, that it isn't a problem of BlockClosure's fork method, but a 
specific behaviour of Transcript. Code you give in your message result 
the same line as VW.


George
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


RE: [Newbies] BlockClosurefork problem

2007-02-20 Thread Ron Teitelbaum
George,

Oh I'm really sorry.  It's funny now that I go back and look I'm
surprised that I missed that.  That's a horse of a different color.  

Basically to answer your question Transcript is not thread safe.  I'm not
sure exactly where it goes wrong but I suspect that it is probably doing a
copy somewhere and if one collection is used as a source and is copied at
the same time with two new additions then one gets lost.

To fix that you can set a semaphore which basically says don't try to access
Transcript from two places at exactly the same time.

semaphore := Monitor new.
[10 timesRepeat: [semaphore critical: [Transcript show: '2']]] fork.
[10 timesRepeat: [semaphore critical: [Transcript show: '1']]] fork.
Transcript cr.

This should make transcript thread safe.

Hope that helps, 

Ron Teitelbaum



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:beginners-
 [EMAIL PROTECTED] On Behalf Of George Herolyants
 Sent: Tuesday, February 20, 2007 3:28 PM
 To: A friendly place to get answers to even the most basic questions
 aboutSqueak.
 Subject: Re: [Newbies] BlockClosurefork problem
 
 Thanks for this answer, Ron. But actually I'm not confused with order in
 wich '1' and '2' presents in result line. I can't understand why in some
 cases this code results ten '1' and ten '2' and in some cases it results
 ten '2' and only nine '1'?
 ___
 Beginners mailing list
 Beginners@lists.squeakfoundation.org
 http://lists.squeakfoundation.org/mailman/listinfo/beginners


___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners