Hello folks,
I am student-teacher of comupter-science and maths and I am writing a thesis for my final exams about a scratch-course. In this course I recognized, that the application of „parallel processing“-blocks like „When I receive _“ and „When Button _ is pressed“ are not really parallel. Let me try to explain this: In an exercise, a referee should give a start-signal to 2 actors, which both should start racing at the same time. This happens due to a mes- sage „start“, the referee is sending to all actors. If the actors receive the message „start“ they both should start to move. Now, if you watch this in slow-motion (Option: single steps), the actors do not act parallel, but one after another. It seems that the cat (Scratch) always starts 1st. Is this intended? Does Scratch/Squeak/Smalltalk support dualcore-processing or do the 2 threads share the whole cpu? How is the processing-time shared and how are the program-parts synchronized? Then we tried to steer an actor with keyboard-inputs, especially with the blocks „When button <Rightarrow> is pressed“ and so on. When you press 2 keys (for example „up“ and „right“) at the same time, scratch ignores the key pressed 1st and only executes the 2nd command, instead of both (moving up and right diagonally). Is there a reason for that? And why is this solution less efficient than an endless repetition that is always scanning if the keys („right“, „up“) are pressed?
Thank you so much for your time and help!
Greetings
Offline
Hello staudi,
I am not an expert on this topic but I know some things. I can help you on the broadcast problem but not the "when [space] key pressed" block.
Lets say you have three scripts:
Script 1:
when green flag clicked
forever
broadcast [step]
end forever
end scriptScript 2:
when I receive [step] change [number1] by (1) end script
Script 3:
when I receive [step] change [number2] by (1) set [equal?] to <number1 = number2> end script
If you start the program you will see that the variable "equal?" always is "true." This is because both the scripts have executed before "equal?" was updated. However, if you move the line "set [equal?] to <number1 = number2>" to script 2 you will see that "equal?" always is "false." This is because script 3 has not executed yet therefore causing the variables to be unequal.
Hope this helps!
P.S. I'm not much of a speech maker, so please tell me if you do not understand something. ;D
Last edited by MathWizz (2010-03-14 15:23:34)
Offline
hmm, Scratch takes about 0.001 seconds to carry out most commands, while I think what you are saying is true, and that only one block is actually active at any time, the time between the scripts is so small that you would not notice it but in very large projects with many scripts. I don't quite understand why this is important to you, so please explain. I know what you mean about the arrow keys, scratch isn't perfect so it looks like you'll have to stick to the forever loop. It many intrest you to know that scratch can only deal with four keys being pressed at once, after that, the keys pressed after the first will be read as open, not closed.
Offline
Hey guyz, thank you so much for your quick answers!
@MathWizz:
In fact, my English isn't really good and I am glad, that you have understood me
. Yes, I had something like this in mind. Thanks for testing it! This shows, that Scratch supports no multicore-processing, only a pseudo-parallelism. But when I take 2 actors for the race, let's say the cat (scratch) and any other, the cat always starts first (is Script 2 in your example). Shouldn't this happen randomly? I hope you undestand why this confuses me.
@sparks:
I just try to figure out, if Scratch can be useful to teach concepts of parellel-processing in school. That's why I want to know how Scratch deals with that and something about the way it is implemented.
Yes it's strange. Unfortunately, the way with the "forever-loop" is much more quicker. Therefore, the pupils don't want to use the blocks that are meant to be used in this way.
The 4-key support is interesting! But what do you mean with open and closed? You mean up and down?
greetz, staudi
Offline
Hi staudi,
you might be interested in this thread about Scratch's implementation of concurrency. Especially John's answer should clarify your issues. After that I think it's safe to claim that Scratch is an excellent tool to introduce students to the concept of concurrency. Please don't hesitate to ask if anything remains unclear.
Offline