Question about multiple thread
Author |
Message |
someguy123
|
Posted: Tue Mar 27, 2007 9:14 pm Post subject: Question about multiple thread |
|
|
is it possible to run several tasks at same times?
like having a timer going and at the same time asking users questions?
if it is possible lmk how plz thx |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Cervantes

|
Posted: Tue Mar 27, 2007 9:46 pm Post subject: RE:Question about multiple thread |
|
|
It is possible with processes, but those are highly discouraged for most purposes.
However, if you are pausing for user input, it might be justified. Probably not, though, as you can just wrap the getch or whatever in a if hasch then.
If that doesn't answer your question, please post back giving more details about your goals. |
|
|
|
|
 |
someguy123
|
Posted: Wed Mar 28, 2007 5:51 am Post subject: Re: Question about multiple thread |
|
|
actually i was trying to make something like this
http://www.compsci.ca/v3/viewtopic.php?t=13089&highlight=star+field
but i thought i needed process to make multiple snow move at the same time
but i dont really understand this program could u tell me how it works and what would i need to learn to make something like this? |
|
|
|
|
 |
Clayton

|
Posted: Wed Mar 28, 2007 11:00 am Post subject: RE:Question about multiple thread |
|
|
the first thing you must realize is that the "stars" are not moving at the same time. Instead, each is moved sequentially. This happens so etremely fast however, that it is not noticeable to the human eye, and we percieve this to be happening all at once. Does that help answer your question? |
|
|
|
|
 |
someguy123
|
Posted: Wed Mar 28, 2007 11:51 am Post subject: Re: RE:Question about multiple thread |
|
|
Freakman @ Wed Mar 28, 2007 11:00 am wrote: the first thing you must realize is that the "stars" are not moving at the same time. Instead, each is moved sequentially. This happens so etremely fast however, that it is not noticeable to the human eye, and we percieve this to be happening all at once. Does that help answer your question?
yes thx, but another question i have is how do u make multiple stars and moving them all in different direction at the same time? |
|
|
|
|
 |
Clayton

|
Posted: Wed Mar 28, 2007 12:35 pm Post subject: RE:Question about multiple thread |
|
|
Freakman's explanation, in my opinion, is not an answer to your question. The thing about a computer is that it never does two things at the same time (unless you've got two CPU's, but we can ignore that). Even if you use processes, the snow flakes are still going to be moved sequentially.
So, here's how you do this. Create an array of snow flakes. Each snow flake will have x and y positions as well as x and y velocities. This data should be stored in a user defined type. Then each time through your loop, you iterate through each snow flake in your array and update the positions and velocities appropriately. Basic particle motion.
edit, from the original author: Holy crap! It appears that I'm logged in as Freakman. I am, in fact, Cervantes. I have no idea how that happened. Uhh... Dan? |
|
|
|
|
 |
Amailer

|
Posted: Wed Mar 28, 2007 6:07 pm Post subject: RE:Question about multiple thread |
|
|
wow what the hell? That - that sounded messed :/ |
|
|
|
|
 |
Andy
|
Posted: Wed Mar 28, 2007 7:46 pm Post subject: Re: Question about multiple thread |
|
|
err no? if you have a video card, graphics rendering is done in parallel. it just depends on how often you send signal to the monitor. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
McKenzie

|
Posted: Wed Mar 28, 2007 9:06 pm Post subject: Re: Question about multiple thread |
|
|
What Andy is saying is that, Wow, how could BOTH Freakmans be wrong about such a basic concept. All of the stars do not "appear" to be moving simultaneously because they are being drawn so quickly. They actually are all moving at the same time. Sure they were rendered to an offscreen buffer in sequence but the View.Update copies the image all at once.
SomeGuy123: Your program actually sounds like a textbook example of a good use of using the Turing fork/process combo. As long as you restict the use of the process to running your timer you should be OK. |
|
|
|
|
 |
Cervantes

|
Posted: Wed Mar 28, 2007 10:22 pm Post subject: RE:Question about multiple thread |
|
|
First, nothing was said about View.Update. He might not be using that. However, that's not my main point, as that would be pretty weak. We can safely assume we're using View.Update.
The point is that each snow flake is handled separately. The new position and velocity is calculated for one snow flake, then for the next, then the next, and so on. It's not all calculated at once, as it is in the real world, per se.
I don't agree with using processes/fork here at all. It's completely unnecessary. How many programs do you see running a separate process for each of n snowflakes? |
|
|
|
|
 |
someguy123
|
Posted: Thu Mar 29, 2007 7:16 am Post subject: Re: RE:Question about multiple thread |
|
|
Freakman @ Wed Mar 28, 2007 12:35 pm wrote: Freakman's explanation, in my opinion, is not an answer to your question. The thing about a computer is that it never does two things at the same time (unless you've got two CPU's, but we can ignore that). Even if you use processes, the snow flakes are still going to be moved sequentially.
So, here's how you do this. Create an array of snow flakes. Each snow flake will have x and y positions as well as x and y velocities. This data should be stored in a user defined type. Then each time through your loop, you iterate through each snow flake in your array and update the positions and velocities appropriately. Basic particle motion.
edit, from the original author: Holy crap! It appears that I'm logged in as Freakman. I am, in fact, Cervantes. I have no idea how that happened. Uhh... Dan?
thx i guess that sort of answered my question, who ever wrote that o.O |
|
|
|
|
 |
Mazer

|
Posted: Thu Mar 29, 2007 7:45 am Post subject: RE:Question about multiple thread |
|
|
Freakman, I think it would help to use the word "concurrently" rather than "sequentially". No, each star isn't moving at the same time, but they each move a little bit often enough to make it seem that way.
Just like on a single processor/single core computer your processes aren't all running at once, but they run for a little bit of time so often that you can't notice the difference.
I would of course go with what Cervantes (and perhaps Freakman?) suggested with respect to drawing stars. But in regards to the timer thing, I think using fork might not be a bad idea. As with any use of fork, you need to be careful.
Your other option would be to use [/i]if hasch then getch[/i] which is really ugly and annoying. I suppose you could wrap that in a function or something, but keep in mind you need to keep track of things like hitting backspace. The best solution would be to use Turing's GUIs. Get answers from the user in a TextField, and if the timer runs out before the user hits Enter or presses a button, disable the field and end the round or whatever.
Andy: Could you elaborate on the video card thing? I really can't see how that applies here. |
|
|
|
|
 |
ericfourfour
|
Posted: Thu Mar 29, 2007 7:36 pm Post subject: RE:Question about multiple thread |
|
|
I think I made a Getter class that could be run in a loop with a timer and everything else. Its in Turing Submissions somewhere. That would be a simple alternative to hasch and getch (although that is probably how it works). |
|
|
|
|
 |
|
|