| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jul 21, 2008 10:56 am Post subject: checking if something has been done in an amount of time |
|
|
Is there anyway to check if something has been done in a certain amount of time? I can really only think of creating one thread that executes a function and another thread that just sleeps, and if the other thread isn't finished in the amount of time it should (the other thread exits before it does) the function being executed in the thread returns an error. Of course, since this has to be done simultaneously, it would have to be done with multi-threading, but that doesn't work if you only have one processor, so how can I do this? Thank you for your comments.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Jul 21, 2008 11:02 am Post subject: |
|
|
| One processor CAN multithread, but not just in parallel. Just make two threads and keep checking from another one if the other thread is done and if time runs out, do whatever you want to.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jul 21, 2008 11:07 am Post subject: |
|
|
Well, I guess it can, but it's not exactly multi-threading. It's more switching between each so incredibly fast you can't even tell.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
Posted: Mon Jul 21, 2008 12:33 pm Post subject: |
|
|
| Depends on what you're actually looking for. Search for WaitForSingleObject()
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jul 21, 2008 12:35 pm Post subject: |
|
|
:O Totally forgot about WaitForSingleObject.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon Jul 21, 2008 1:14 pm Post subject: |
|
|
| What about GetTickCount?
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Tue Jul 22, 2008 6:22 am Post subject: |
|
|
| Jani wrote: | | One processor CAN multithread, but not just in parallel. Just make two threads and keep checking from another one if the other thread is done and if time runs out, do whatever you want to. |
That would cause deadlock. EX: Thread 1 waits for Thread 2 to terminate. Thread 2 can't terminate cause it's waiting for Thread 1 to terminate. Both threads are in a suspended state and your program freezes.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Jul 22, 2008 7:26 am Post subject: |
|
|
| rapion124 wrote: | | EX: Thread 1 waits for Thread 2 to terminate. Thread 2 can't terminate cause it's waiting for Thread 1 to terminate. | I didn't say T1 would wait T2 and vice versa, did I? -_- I mean that T1 waits untill T2 is done, or if time runs out at T1, it just kills T2, or something -> no deadlocks.
|
|
| Back to top |
|
 |
Ksbunker Advanced Cheater
Reputation: 0
Joined: 18 Oct 2006 Posts: 88
|
Posted: Tue Jul 22, 2008 9:37 am Post subject: re: |
|
|
pseudo...
| Code: | expected = 1000 ; ms
Start = GetTickCount()
; do what you want
End = GetTickCount()
Elasped = End - Start
COMPARE elasped vs. expected
if bigger... too long
if smaller... good |
|
|
| Back to top |
|
 |
|