well i need to use a standard function for a time delay...i came across sleep() but it works n unix but m workin on windows usin dev c++...nd dev cant recogniz sleep() though i included unistd.h,dos.h,....now i dnt want ne platform specific solution but a standard one....please help......
9 13079 Banfa 9,065
Expert Mod 8TB
There is no standard portable sleep function, *nix has sleep Windows has Sleep.
If you want a platform portable pause you will have to write a function to do it using standard library functions such as time(...)
There is no standard portable sleep function, *nix has sleep Windows has Sleep.
All unixes also have the Posix thread library (pthread) I don't know if there's
a MS Windows implementation available (although MS Windows claims to be
Posix compliant). The pthread library offers the pthread_cond_timedwait function
which can very well be used for an ordinary sleep() functionality.
If you want a platform portable pause you will have to write a function to do it using standard library functions such as time(...)
You're not suggesting a 'busy wait' are you? -)
kind regards,
Jos
but if i use custom made sleep using time() i will b wasting valuable cpu cylcles....and its behaviour will be too unpredictable....
one more thn....i tried to use delay() by includin dos.h.........but it didnt work on mingw usin devcpp....it cant recognize the function even...thnk mingw ddnt support it...!!! ne idea...
All unixes also have the Posix thread library (pthread) I don't know if there's
a MS Windows implementation available (although MS Windows claims to be
Posix compliant). The pthread library offers the pthread_cond_timedwait function
which can very well be used for an ordinary sleep() functionality.
There is a native Win32 pthreads implementation:
http://sourceware.org/pthreads-win32/
There are also various other cross-platform libraries that can accomplish what you're looking for. For example, wxWidgets has a function called wxMilliSleep that does what you need.
MS Windows does not exactly claim to be Posix-compliant. Windows NT was compliant with an earlier, less extensive Posix specification. I don't know if the same applies to later versions, and no version has ever claimed to be compliant with the more recent and comprehensive Posix standards.
There is a native Win32 pthreads implementation:
http://sourceware.org/pthreads-win32/
There are also various other cross-platform libraries that can accomplish what you're looking for. For example, wxWidgets has a function called wxMilliSleep that does what you need.
MS Windows does not exactly claim to be Posix-compliant. Windows NT was compliant with an earlier, less extensive Posix specification. I don't know if the same applies to later versions, and no version has ever claimed to be compliant with the more recent and comprehensive Posix standards.
Ah, ok, so I guess all bets are off then when it comes to any current MS Windows
compliancy w.r.t. any of the latest Posix Standards?
What a mess this world is ...;-)
kind regards,
Jos
Well, according to Wikipedia, the NT-based versions of Windows are Posix-compliant as long as you install Microsoft Windows Services for UNIX. I don't know how well that works.
UNIX-type operating systems support a lot more types of compatibility than just Posix, of course. To get an idea of the significance of this, consider that (again according the Wikipedia), while XP with MSW Services for UNIX is fully Posix-compliant, the list of those that are not officially compliant includes FreeBSD, NetBSD, OpenBSD and most Linux distros. Also, just because MS supports Posix interfaces doesn't mean it has quality implementations.
what about using:
#ifdef WIN32
#include <windows.h> // needed for Sleep
#else
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bill ramsay |
last post by:
Dear all.
I am using an existing hodge-podge of an application that runs on top
of an Access database. This application dials up customer equipment,
handshakes then downloads/uploads various...
|
by: Santa |
last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in
the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx
to increase the performance of my ASPX...
|
by: Alo Sarv |
last post by:
Hi
From what I have understood from various posts in this newsgroup, writing event
loops pretty much comes down to this:
while (true) {
handleEvents();
sleep(1); // or _sleep() or...
|
by: Alasdair |
last post by:
Friends,
I'm an old C programmer who upgraded to C++ but was never
comfortable with it. I've recently moved to C# and love
it but I obviously am missing some of the subtleties. I
thought the...
|
by: Santa |
last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in
the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx
to increase the performance of my ASPX...
|
by: OlafMeding |
last post by:
Below are 2 files that isolate the problem. Note, both programs hang
(stop responding) with hyper-threading turned on (a BIOS setting), but
work as expected with hyper-threading turned off.
...
|
by: nmsreddi |
last post by:
Hi friends
I am working on c#.net . i am developing a windows application using c# 2003
aim of my application is sending and receiving sms using GSM modem.
for this i am using AxMscomm...
|
by: lewisms |
last post by:
Hello all,
I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
|
by: Dick Moores |
last post by:
Windows XP Pro, Python 2.5.1
import msvcrt
while True:
if msvcrt.kbhit():
key = msvcrt.getch()
if key == 'Enter'
do something
Is there a way to catch the pressing of the 'Enter' key?
|
by: Charles Zhang |
last post by:
Sleep() function Sleep at lease 1 millisecond, there is a way to make a
thread to sleep less than a millisecond? One way I know of is using
performance counter which is not really sleep ( loop and...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |