ledeni
asked on
Unix threads and Sleep as a block process
Hi everyone ... thanks for taking your time to look at this ...
I am trying to create a process that creates a needed number of threads per single proces. Also, within this main process I have a 2 global vars that are accessed within threads as well as main process. Those 2 vars I am controling using the POSIX semaphores. I am shure that those semaphores are working and positioned right.
My problem is that I have to use the sleep within my main process to let those threads kick in to read / change the global vars. Since sleep blocks the entire process my program kind of run VERY slow.
My main loop looks like
while(time)
{
sem_wait(¤time)
currenttime++
sem_post(¤time)
while(true)
{
create my thread etc etc
sleep(1)
}
}
I was wondering if anyone is out there that is aware of any system call that would not block the entire process that I could use instead of sleep ....
Again ... thanks a loot for looking at this.
L.
I am trying to create a process that creates a needed number of threads per single proces. Also, within this main process I have a 2 global vars that are accessed within threads as well as main process. Those 2 vars I am controling using the POSIX semaphores. I am shure that those semaphores are working and positioned right.
My problem is that I have to use the sleep within my main process to let those threads kick in to read / change the global vars. Since sleep blocks the entire process my program kind of run VERY slow.
My main loop looks like
while(time)
{
sem_wait(¤time)
currenttime++
sem_post(¤time)
while(true)
{
create my thread etc etc
sleep(1)
}
}
I was wondering if anyone is out there that is aware of any system call that would not block the entire process that I could use instead of sleep ....
Again ... thanks a loot for looking at this.
L.
Hi ledeni,
I think if you put (move/link) this question to UNIX programming, you might get better
response.
http://oldlook.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/
You can ask the CS (post a 0 point question in CS TA), and the Mods will do it for you:
http://oldlook.experts-exchange.com/Community_Support/
I think if you put (move/link) this question to UNIX programming, you might get better
response.
http://oldlook.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/
You can ask the CS (post a 0 point question in CS TA), and the Mods will do it for you:
http://oldlook.experts-exchange.com/Community_Support/
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry I should have posted earlier ... but I got that solved with thr_yield() ... but certanly your effort will be awarded !!
Thanks for looking at this anyhow
Thanks for looking at this anyhow
ledeni,
I had suggested using pthread_yield more than 2 weeks ago !!! I assumed that you were using pthreads which was wrong ... so you had to use thr_yield in place of pthread_yield ... I feel that you awarded the question wrongly
I had suggested using pthread_yield more than 2 weeks ago !!! I assumed that you were using pthreads which was wrong ... so you had to use thr_yield in place of pthread_yield ... I feel that you awarded the question wrongly
ASKER
Hey Pasha
fare is fare ... you can move or split those points between the both guys .. I appreciate the sunny's response though that it was not quite the right reposnse .. since I used the thr_yield() and I also appreciate the other guy response for giving in his time .. .I will leave it to you to distribute those points ...
thx
L .
fare is fare ... you can move or split those points between the both guys .. I appreciate the sunny's response though that it was not quite the right reposnse .. since I used the thr_yield() and I also appreciate the other guy response for giving in his time .. .I will leave it to you to distribute those points ...
thx
L .
ASKER
for a future reference ,let me know if there is anyhow possible for me to reasign points or split them my self bw different people .
thanks
L.
thanks
L.
>I appreciate the sunny's response though that it was not quite the right reposnse
My idea was correct .... making the threads yield
I had clearly mentioned in my post
>>try pthread_yield()
>>man pthread_yield
>>I assumed that you are using the pthreads library
you never returned clarifying that you were not using pthreads nor was any such thing specified in your original question !! All that was needed was using the corresponding thread yielding function of the library/pltform that you were using.
>for a future reference ,let me know if there is anyhow possible for me to reasign points or split them my self bw different
>people .
you cannot reassign points ... for help with splitting,
https://www.experts-exchange.com/help/closing.jsp
My idea was correct .... making the threads yield
I had clearly mentioned in my post
>>try pthread_yield()
>>man pthread_yield
>>I assumed that you are using the pthreads library
you never returned clarifying that you were not using pthreads nor was any such thing specified in your original question !! All that was needed was using the corresponding thread yielding function of the library/pltform that you were using.
>for a future reference ,let me know if there is anyhow possible for me to reasign points or split them my self bw different
>people .
you cannot reassign points ... for help with splitting,
https://www.experts-exchange.com/help/closing.jsp
I split the points per asker request.
Yensidmod
EE Moderator
Yensidmod
EE Moderator
have a look at the following page, to see if it make sense:
http://oldlook.experts-exchange.com/questions/20577083/Need-a-milisecond-timer.html