Thread problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Thread problem

Stéphane Ducasse
Hi all

I'm working on a threadSafeTranscript and I could not understand why  
the following code
does not print something else than

        1*100-102-103-104-105-106-107-108-109-110-

|tt|
tt := Transcript.
[1 to: 10 do: [:i | tt show: i printString; show: '*'.
                                        Processor yield ].
        tt flush ]  fork.
[100 to: 110 do: [:i | tt show: i printString; show: '-'.
                                        Processor yield  ].
        tt flush ] fork.

Stef

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Thread problem

Igor Stasenko
2009/3/29 Stéphane Ducasse <[hidden email]>:

> Hi all
>
> I'm working on a threadSafeTranscript and I could not understand why
> the following code
> does not print something else than
>
>        1*100-102-103-104-105-106-107-108-109-110-
>
> |tt|
> tt := Transcript.
> [1 to: 10 do: [:i | tt show: i printString; show: '*'.
>                                        Processor yield ].
>        tt flush        ]  fork.
> [100 to: 110 do: [:i | tt show: i printString; show: '-'.
>                                        Processor yield  ].
>        tt flush        ] fork.
>

What you expecting from it?
If you imagine that Processes running in parallel, then numbers can be
in any order , as well as * and - characters.
Or you mean, that it eating 2-10 numbers which should be printed?
In this case, the source of inconsistency could be the #flush method.
But its hard to say, without looking at source code.

> Stef
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Thread problem

Igor Stasenko
2009/3/29 Igor Stasenko <[hidden email]>:

> 2009/3/29 Stéphane Ducasse <[hidden email]>:
>> Hi all
>>
>> I'm working on a threadSafeTranscript and I could not understand why
>> the following code
>> does not print something else than
>>
>>        1*100-102-103-104-105-106-107-108-109-110-
>>
>> |tt|
>> tt := Transcript.
>> [1 to: 10 do: [:i | tt show: i printString; show: '*'.
>>                                        Processor yield ].
>>        tt flush        ]  fork.
>> [100 to: 110 do: [:i | tt show: i printString; show: '-'.
>>                                        Processor yield  ].
>>        tt flush        ] fork.
>>
>
> What you expecting from it?
> If you imagine that Processes running in parallel, then numbers can be
> in any order , as well as * and - characters.
> Or you mean, that it eating 2-10 numbers which should be printed?
> In this case, the source of inconsistency could be the #flush method.
> But its hard to say, without looking at source code.
>

oh, and if you running it in image, without Eliot's closures, i'd
recommend to use separate iterator for cycles, because it might be the
case that parser using the same temp slot for 'i' temp in both blocks.

>> Stef
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Thread problem

Stéphane Ducasse
Igor

I m not surprised of the order. I know that transcript is totally  
unsafe :)
Now this is probably the unclosure stuff that bites me... :)
...stef jumping to pharo and trying ...

stef back

        | tt |
        Smalltalk at: #STranscript ifAbsent: [self  
installThreadSafeAsSTranscript].
        tt := (Smalltalk at: #STranscript).
        tt open.
        [1 to: 10 do: [:x | tt nextPutAll: x printString; nextPutAll: '*'.
                                        Processor yield ] fixTemps.
        tt flush ]  fork.
        [100 to: 110 do: [:i | tt nextPutAll: i printString; nextPutAll: '-'.
                                        Processor yield  ] fixTemps.
        tt flush ] fork.

1*100-2*101-3*102-4*103-5*104-6*105-7*106-8*107-9*108-10*109-110-

So I want closure.....
definitively.

Stef


On Mar 29, 2009, at 4:54 PM, Igor Stasenko wrote:

> 2009/3/29 Igor Stasenko <[hidden email]>:
>> 2009/3/29 Stéphane Ducasse <[hidden email]>:
>>> Hi all
>>>
>>> I'm working on a threadSafeTranscript and I could not understand why
>>> the following code
>>> does not print something else than
>>>
>>>        1*100-102-103-104-105-106-107-108-109-110-
>>>
>>> |tt|
>>> tt := Transcript.
>>> [1 to: 10 do: [:i | tt show: i printString; show: '*'.
>>>                                        Processor yield ].
>>>        tt flush        ]  fork.
>>> [100 to: 110 do: [:i | tt show: i printString; show: '-'.
>>>                                        Processor yield  ].
>>>        tt flush        ] fork.
>>>
>>
>> What you expecting from it?
>> If you imagine that Processes running in parallel, then numbers can  
>> be
>> in any order , as well as * and - characters.
>> Or you mean, that it eating 2-10 numbers which should be printed?
>> In this case, the source of inconsistency could be the #flush method.
>> But its hard to say, without looking at source code.
>>
>
> oh, and if you running it in image, without Eliot's closures, i'd
> recommend to use separate iterator for cycles, because it might be the
> case that parser using the same temp slot for 'i' temp in both blocks.
>
>>> Stef
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project