From: Adrien M. <ie...@ou...> - 2003-02-24 06:27:18
|
Thanks for your complete and quick answer ( even if it was a little bit sarcastic, but I guess I deserved it ;o) ). You were right about the nanosleep. I misunderstood the code ( which is supposed to measure the CPU's frequency, and other stuff), in fact, there was 2 structures in it, one unused with a 1ns interval, the second with a 1s interval... Now it is compiling and working just fine with mingw. And thanks for the explanations of the differences between cygwin and mingw ;) Thanks again, Adrien -----Original Message----- From: min...@li... [mailto:min...@li...] On Behalf Of Oscar Fuentes Sent: Sunday, February 23, 2003 11:21 PM To: min...@li... Subject: Re: [Mingw-users] unknown reference to nanosleep ?? Adrien Mercier <ie...@ou...> writes: > Hi, > > I am trying to compile some source code picked up from the net, > because i will have to adapt it to fit my own needs. My goal is to > obtain a dll as small as possible. > > The problem is this program is using the nanosleep function, and this > function is definitly needed for the algorithm in itsef ( i cannot > afford to take sleep for example, because i need to sleep just for a > nanosecond). This is nonsense. Todays fastest PC's have a CPU cycle of about 0.3 ns. Even if that function is an instrinsic, whatever setup it needs to do for performing its task takes more than a nanosecond. For this kind of job you will need special CPU support (not provided by x86, AFAIK) or carefully code a good bunch of extremely complex machine code. OTOH, on a preemptive non real time OS like Windows, you can't guarantee *any* degree of accuracy while performing waits, except perhaps for kernel-level code. I guess that 'nanosleep' is just 'sleep' with a time interval specified as ns. The 1 second resolution of the *nix 'sleep' is too coarse and possibly the implementors of nanosleep just wanted to create something that will not become obsolete on the coming decades. > When I try to compile it using mingw, i got the "undefined reference" > to nanosleep, even though the time.h is in the include of the file. I > guess this function is not implemented yet. If it is a *nix function, it is normal that Cygwin implements it. Cygwin tries to emulate a POSIX environment on Windows. MinGW, OTOH, is "just" a development kit for developing *native* Windows applications. Don't hold your breath until somebody contributes it, much less until it becomes part of the standard MinGW distribution. > Thus i tried cygwin, and I succeded ( i'm not THAT bad ;) ) but the > problem is now that as i will have to distribute this program as a > DLL, i will have to distribute with it CYGWIN's dll, which is quite > huge ( > 888Ko...) and that definitly doesn't suits my needs. > > Thus, here are my questions : > -Is it possible not to have to distribute the cygwin's dll along with > program builded with cygwin or programs using dll made with cygwin ? As Cygwin's source code is available, possibly you can build a static version of the library. I don't know for sure. Anyways, this is not the correct forum for asking about Cygwin. Try its own mailing lists. > -Is there any way to get the nanosleep function work with mingw ? For 1 nanosecond resolution? Naaa :-) > -Is there any other gcc compiler for windows out there that can meet > both these requirements ? The problem is not the compiler. It is the function. First of all, check that the function is supposed to do what you want to do. Sometimes function's names and parameter specifications are misleading about its real purpose. The 'Sleep' Win32 function, for instance, takes the time interval as milliseconds. Its accuracy is far from being into the millisecond range, though. For instance, this piece of code #include <windows.h> int main() { for(unsigned i = 0; i < 1000; ++i) Sleep(4); } needs 10.5 seconds to run on my system, when it should run on 4 seconds. I'm curious about a similar test with your 'nanosecond' function. > The source code i'm trying to compiled is supposed to be compatible > with "both linux and windows gcc". Lots of old source code packages says "windows gcc" when they mean Cygwin's gcc. -- Oscar ------------------------------------------------------- This SF.net email is sponsored by: SlickEdit Inc. Develop an edge. The most comprehensive and flexible code editor you can use. Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial. www.slickedit.com/sourceforge _______________________________________________ MinGW-users mailing list Min...@li... You may change your MinGW Account Options or unsubscribe at: https://lists.sourceforge.net/lists/listinfo/mingw-users |
From: Luke D. <cod...@ho...> - 2003-02-24 06:59:58
|
>From: Oscar Fuentes <of...@wa...> >Reply-To: Min...@li... >To: min...@li... >Subject: Re: [Mingw-users] unknown reference to nanosleep ?? >Date: 24 Feb 2003 06:21:23 +0100 > >Adrien Mercier <ie...@ou...> writes: > > > Hi, > > > > I am trying to compile some source code picked up from the net, because > > i will have to adapt it to fit my own needs. My goal is to obtain a dll > > as small as possible. > > > > The problem is this program is using the nanosleep function, and this > > function is definitly needed for the algorithm in itsef ( i cannot > > afford to take sleep for example, because i need to sleep just for a > > nanosecond). > >This is nonsense. Todays fastest PC's have a CPU cycle of about 0.3 >ns. Even if that function is an instrinsic, whatever setup it needs to >do for performing its task takes more than a nanosecond. For this kind >of job you will need special CPU support (not provided by x86, AFAIK) >or carefully code a good bunch of extremely complex machine code. > >OTOH, on a preemptive non real time OS like Windows, you can't >guarantee *any* degree of accuracy while performing waits, except >perhaps for kernel-level code. > >I guess that 'nanosleep' is just 'sleep' with a time interval >specified as ns. The 1 second resolution of the *nix 'sleep' is too >coarse and possibly the implementors of nanosleep just wanted to >create something that will not become obsolete on the coming decades. > > > When I try to compile it using mingw, i got the "undefined > > reference" to nanosleep, even though the time.h is in the include of > > the file. I guess this function is not implemented yet. > >If it is a *nix function, it is normal that Cygwin implements >it. Cygwin tries to emulate a POSIX environment on Windows. MinGW, >OTOH, is "just" a development kit for developing *native* Windows >applications. Don't hold your breath until somebody contributes it, >much less until it becomes part of the standard MinGW distribution. > > > Thus i tried cygwin, and I succeded ( i'm not THAT bad ;) ) but the > > problem is now that as i will have to distribute this program as a DLL, > > i will have to distribute with it CYGWIN's dll, which is quite huge ( > > 888Ko...) and that definitly doesn't suits my needs. > > > > Thus, here are my questions : > > -Is it possible not to have to distribute the cygwin's dll along with > > program builded with cygwin or programs using dll made with cygwin ? > >As Cygwin's source code is available, possibly you can build a static >version of the library. I don't know for sure. Anyways, this is not >the correct forum for asking about Cygwin. Try its own mailing lists. The Cygwin nanosleep just converts the time to milliseconds anyway (as you would expect): DWORD req = rqtp->tv_sec * 1000 + (rqtp->tv_nsec + 500000) / 1000000; DWORD start_time = GetTickCount (); DWORD end_time = start_time + req; syscall_printf ("nanosleep (%ld)", req); int rc = pthread::cancelable_wait (signal_arrived, req); Therefore, if your program works under Cygwin then just use Sleep(). > > > -Is there any way to get the nanosleep function work with mingw ? > >For 1 nanosecond resolution? Naaa :-) > > > -Is there any other gcc compiler for windows out there that can meet > > both these requirements ? > >The problem is not the compiler. It is the function. First of all, >check that the function is supposed to do what you want to >do. Sometimes function's names and parameter specifications are >misleading about its real purpose. The 'Sleep' Win32 function, for >instance, takes the time interval as milliseconds. Its accuracy is far >from being into the millisecond range, though. For instance, this >piece of code > >#include <windows.h> > >int main() { > for(unsigned i = 0; i < 1000; ++i) > Sleep(4); >} > >needs 10.5 seconds to run on my system, when it should run on 4 >seconds. I'm curious about a similar test with your 'nanosecond' >function. The default resolution of 10 ms can be changed to as little as 1 ms by calling timeBeginPeriod(). The MSDN documentation on "Multimedia Timers" explains the limitations and the proper checks you need when changing the resolution. You might think that those functions in mmsystem.h would not have an effect on the kernel32 function Sleep(), but I have found that they do. > > > The source code i'm trying to compiled is supposed to be compatible > > with "both linux and windows gcc". > >Lots of old source code packages says "windows gcc" when they mean >Cygwin's gcc. > >-- >Oscar Luke _________________________________________________________________ Hotmail now available on Australian mobile phones. Go to http://ninemsn.com.au/mobilecentral/hotmail_mobile.asp |