usleep

Sleeping in a Thread (C / POSIX Threads)

≯℡__Kan透↙ 提交于 2019-11-30 14:49:10
问题 I am developing a multithreaded application that makes use of POSIX Threads. I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which results in termination of the main application (by default). Here is my pseudo code: void threaded_task(void *ptr) { initialize(); while(running) { do_the_work();

Sleeping in a Thread (C / POSIX Threads)

戏子无情 提交于 2019-11-30 12:38:09
I am developing a multithreaded application that makes use of POSIX Threads . I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which results in termination of the main application (by default). Here is my pseudo code: void threaded_task(void *ptr) { initialize(); while(running) { do_the_work(); usleep(some_interval); } clean_up(); release_resources(); } And here is the pseudo function that is

implicit declaration of function usleep

∥☆過路亽.° 提交于 2019-11-30 03:03:31
gcc (GCC) 4.6.3 c89 I am trying to use usleep . However, I keep getting the following warning: implicit declaration of function usleep I have included the unistd.h header file. The man pages mentions something about this. But I am not sure I understand by it: usleep(): Since glibc 2.12: _BSD_SOURCE || (_XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) Before glibc 2.12: _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED But not sure what I a to do with the above? paxdiablo That list is the pre

What is a practical use for PHP's sleep()?

浪尽此生 提交于 2019-11-29 21:15:14
I just had a look at the docs on sleep() . Where would you use this function? Is it there to give the CPU a break in an expensive function? Any common pitfalls? One place where it finds use is to create a delay . Lets say you've built a crawler that uses curl / file_get_contents to get remote pages. Now you don't want to bombard the remote server with too many requests in short time. So you introduce a delay between consecutive requests. sleep takes the argument in seconds, its friend usleep takes arguments in microseconds and is more suitable in some cases. Another example: You're running

implicit declaration of function usleep

≡放荡痞女 提交于 2019-11-29 00:07:28
问题 gcc (GCC) 4.6.3 c89 I am trying to use usleep . However, I keep getting the following warning: implicit declaration of function usleep I have included the unistd.h header file. The man pages mentions something about this. But I am not sure I understand by it: usleep(): Since glibc 2.12: _BSD_SOURCE || (_XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) Before glibc 2.12: _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE

What is a practical use for PHP's sleep()?

雨燕双飞 提交于 2019-11-28 17:20:56
问题 I just had a look at the docs on sleep(). Where would you use this function? Is it there to give the CPU a break in an expensive function? Any common pitfalls? 回答1: One place where it finds use is to create a delay . Lets say you've built a crawler that uses curl / file_get_contents to get remote pages. Now you don't want to bombard the remote server with too many requests in short time. So you introduce a delay between consecutive requests. sleep takes the argument in seconds, its friend

c++, usleep() is obsolete, workarounds for Windows/MingW?

为君一笑 提交于 2019-11-26 18:50:45
I already found out with another question that Windows/MingW doesn't provide the nanosleep() and setitimer() alternatives to the obsolete usleep(). But my goal is to fix all warnings that cppcheck gives me, including the usleep() style warnings. So, is there a workaround to somehow avoid usleep() on Windows without using cygwin or installing loads of new dependencies/libraries? Thanks. usleep() works with microseconds. In windows for getting microsecond precesion you should use QueryPerformanceCounter() winapi function. Here you can find how get that precesion using it. I used this code from

c++, usleep() is obsolete, workarounds for Windows/MingW?

走远了吗. 提交于 2019-11-26 06:37:15
问题 I already found out with another question that Windows/MingW doesn\'t provide the nanosleep() and setitimer() alternatives to the obsolete usleep(). But my goal is to fix all warnings that cppcheck gives me, including the usleep() style warnings. So, is there a workaround to somehow avoid usleep() on Windows without using cygwin or installing loads of new dependencies/libraries? Thanks. 回答1: usleep() works with microseconds. In windows for getting microsecond precesion you should use