Wait...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ozguxxx

Wait...

Post by Ozguxxx »

Hi, I am just surprised with the fact that I cannot just call same sleep(int millisecs) function from simultaneously running threads. When I try they jump to same codes and change each other's local variables in function. To be clearer when one thread is preempted in sleep() function and then when some other thread is run and called wait() function, it cahnges other thread's local variable in function so both threads do not run logically I mean results are unpredictable... My quesiton is how can I avoid this? I know that this is about mutual exclusion, and synchronization stuff and you should tell me "Go & read tanenbaum" but I just want to have some idea, I currently dont have time to read docs about this bloody and hard subject... ;D Thanx...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Wait...

Post by distantvoices »

Hi, gosh,

I suggest you send the threads to sleep via scheduler so that they are in state "SLEEPING". You put the sleeping threads in a certain queue the timer task scans throu' to check if the time a thread has to sleep has passed by and then the timer task sets this thread to state runnable and removes it from the sleeping queue.

thus you won't need any variables - a Time_to_sleep field in the process structure. the timer task shall decrement this field - about checking it see above.

the timer task you should wake up via timer interrupt after a certain time has passed by cuz there could be some work accumulated. scanning the sleeping threads for ex.

stay safe.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Ozguxxx

Re:Wait...

Post by Ozguxxx »

Hey a really good idea, by doing in that way we wont have to run the thread that is sleeping... Thanx... Any ideas are still welcome... :)
Post Reply