Ending a Process?
Author |
Message |
Kelsey
|
Posted: Thu Jan 06, 2005 6:05 pm Post subject: Ending a Process? |
|
|
After I use fork to begin running a process, how do I end it? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
MihaiG
|
Posted: Thu Jan 06, 2005 6:14 pm Post subject: (No subject) |
|
|
possibly
??? |
|
|
|
|
|
Cervantes
|
Posted: Thu Jan 06, 2005 6:50 pm Post subject: (No subject) |
|
|
ELCOMANDANTE wrote:
Nope. Use return and a flag variable.
AsianSensation wrote:
Yeah, I should have said it earlier, guess I forgot, sorry.
but things like this:
code: |
var flag : boolean := false
process doSomething
if flag = true then
return
end if
put "Hello"
end doSomething
for rep : 1 .. 100
put "Hi"
fork doSomething
if rep > 20 then
flag := true
end if
end for
|
return will terminates the process.
|
|
|
|
|
|
Martin
|
Posted: Thu Jan 06, 2005 6:54 pm Post subject: (No subject) |
|
|
Don't use processes. |
|
|
|
|
|
Kelsey
|
Posted: Thu Jan 06, 2005 7:03 pm Post subject: (No subject) |
|
|
martin wrote: Don't use processes.
Then how would you suggest I run a timer in my program?
And to the other two of you, thnaks! |
|
|
|
|
|
Cervantes
|
Posted: Thu Jan 06, 2005 7:10 pm Post subject: (No subject) |
|
|
Kelsey wrote: martin wrote: Don't use processes.
Then how would you suggest I run a timer in my program?
You could put it in your main loop. What do you mean when you say a "timer", however? A timer since the program has started (or since some event occured)? Time.Elapsed, inside your main loop, will work fine. |
|
|
|
|
|
Kelsey
|
Posted: Thu Jan 06, 2005 7:17 pm Post subject: (No subject) |
|
|
Cervantes wrote:
You could put it in your main loop. What do you mean when you say a "timer", however? A timer since the program has started (or since some event occured)? Time.Elapsed, inside your main loop, will work fine.
It starts when an even occurs. How do I encorperate Time.Elapsed so it can be outputed in the run window? |
|
|
|
|
|
Cervantes
|
Posted: Thu Jan 06, 2005 7:24 pm Post subject: (No subject) |
|
|
huh?
Or, a little more complex:
code: |
for i : 1 .. 100
delay (10)
locate (1, 1)
put "Current Time: ", Time.Elapsed
end for
var event_occured_at := Time.Elapsed
locate (2, 1)
put "Event \"for loop complete\" occured at ", event_occured_at
loop
locate (3, 1)
put "Time Since event occured : ", Time.Elapsed - event_occured_at
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Martin
|
Posted: Thu Jan 06, 2005 7:26 pm Post subject: (No subject) |
|
|
Well, you have your main loop keep track of the time that has elapsed since the beginning of the program.
Each event is then tied to a start time, and has a life, and this is all checked in the main loop. It's much cleaner.
In pseudocode:
code: | while (not gameOver())
totalTime = Time.Elapsed - startTime
checkEventsForTimeBasedConditions()
....
end while |
|
|
|
|
|
|
Kelsey
|
Posted: Thu Jan 06, 2005 7:28 pm Post subject: (No subject) |
|
|
Cervantes wrote: huh?
Or, a little more complex:
code: |
for i : 1 .. 100
delay (10)
locate (1, 1)
put "Current Time: ", Time.Elapsed
end for
var event_occured_at := Time.Elapsed
locate (2, 1)
put "Event \"for loop complete\" occured at ", event_occured_at
loop
locate (3, 1)
put "Time Since event occured : ", Time.Elapsed - event_occured_at
end loop
|
This doesn't really seem like what I'm trying to do, but thanks for explaining that. Why is it so bad to use processes anyways? |
|
|
|
|
|
Martin
|
Posted: Thu Jan 06, 2005 7:34 pm Post subject: (No subject) |
|
|
Processes behave somewhat inconsistantly and unpredictably, and are often used inefficiently.
The basic idea of writing a program is to perform as few calculations as necissary, and when people use processes, 99% of the time, they are calculating something over and over, and only using that calculation a couple of times. |
|
|
|
|
|
Kelsey
|
Posted: Thu Jan 06, 2005 7:43 pm Post subject: (No subject) |
|
|
martin wrote: Processes behave somewhat inconsistantly and unpredictably, and are often used inefficiently.
The basic idea of writing a program is to perform as few calculations as necissary, and when people use processes, 99% of the time, they are calculating something over and over, and only using that calculation a couple of times.
code: |
process timer %Timer for the game, runs parallel later when game is begun
loop
time_count := time_count + 1
time_count2 := intstr (time_count)
delay (1000)
drawfillbox (140, 240, 180, 260, 7)
Font.Draw (time_count2, 145, 245, font, brightred)
exit when time_count = 999
end loop
end timer
. . .
%Bunch of other stuff here
. . .
loop
Mouse.Where (x, y, b)
if b = 1 and x < 120 and x > 80 and y < 275 and y > 235 then
fork timer
drawfillbox (80, 235, 120, 275, 25)
Font.Draw ("STOP", 83, 250, font, black)
. . .
Bunch more stuff
. . .
end loop
|
Basically, when you click the button to start the game (Minesweeper), the timer needs to begin. What I wanted to do was end the process when the button is clicked again (it changes to a stop button once the game begins).
I have a lot of conditions that need to be checked continuosly throughout the loop, so adding a delay in there for my time to show up every second wouldn't be so great. I think using a process here works . |
|
|
|
|
|
Cervantes
|
Posted: Thu Jan 06, 2005 8:00 pm Post subject: (No subject) |
|
|
Kelsey wrote:
I have a lot of conditions that need to be checked continuosly throughout the loop, so adding a delay in there for my time to show up every second wouldn't be so great. I think using a process here works.
Nah:
code: |
var elapsedSeconds := 0
loop
%do stuff
%do drawing stuff
if Time.Elapsed >= elapsedSeconds * 1000 then
elapsedSeconds += 1
locate (1, 1)
put elapsedSeconds
end if
%have your View.Update and delay here
end loop
|
|
|
|
|
|
|
Kelsey
|
Posted: Thu Jan 06, 2005 8:05 pm Post subject: (No subject) |
|
|
Thank-you! |
|
|
|
|
|
|
|