We would implement only one sleep function accepting a double value then liek expressed previously would decompose into secs, nsecs
// thread sleep for secs seconds, return true if sucessful false otherwise
Example implementation for the discussed unix side case (only for now) not relying on usleep() and still high precision one-size-fits-all sleep:
#include <errno.h>
#include <time.h>
bool fl_sleep_ux(double secs)
{
struct timespec tv;
tv.tv_sec = (time_t) secs;
tv.tv_nsec = (long) ((secs - tv.tv_sec) * 1E9);
return nanosleep(&tv, &tv)==0 ? true : false;
}
-Fab
> Example implementation for the discussed unix side case (only
> for now) not relying on usleep() and still high precision
> one-size-fits-all sleep:
>
> #include <errno.h>
>
> #include <time.h>
>
> bool fl_sleep_ux(double secs)
>
> {
>
> struct timespec tv;
>
> tv.tv_sec = (time_t) secs;
>
> tv.tv_nsec = (long) ((secs - tv.tv_sec) * 1E9);
>
> return nanosleep(&tv, &tv)==0 ? true : false;
>
> }
Such an implementation would not be backward compatible too. And the
caller must handle interruptions by signals itself.
time it was part of the POSIX realtime extension and we must expect
that some supported systems don't implement it. Later it was moved
to the Timers open, this means it was still no mandatory function.
It became mandatory as part of the POSIX.1 Base not before the latest
version from 2008.
Therefore we need a fallback in any case and this fallback is likely
not thread-safe out-of-the-box. So we should first think whether this
is required/desired or not. If not, 'usleep()' can be considered as
the fallback or maybe the FLTK timer callback facility.
I think Albrecht is right when he looks closely at the ABI. This is
important and all users of the shared library will suffer otherwise.
And I agree with Albrecht too, that things like the delay stuff are
not really related to the primary job FLTK is intended for.
Therefore one can consider it as a kind of bloat for all users that
don't need it. And not being bloated is *the* fundamental difference
of FLTK compared to other GUI toolkits!
But I agree with you, that a portable delay function would be an
example for code that should not be reinvented again and again in
every new project - because a portable implementation is nontrivial.
The lightweight UTF-8 normalization code that I have posted here
some time ago is another example of such stuff. Useful *if* you
need it, but simply bloat otherwise.
To preserve the "L" in FLTK, I think if we really want to add such
code, it should go into a separate auxiliary library similar to the
image stuff (that can be linked only if needed). What do the others
think about going this way in general?
Hi Fabien,
Regardless of what you or I may think about using shared objects, there’s no doubt that right here, right now, that *is* the way the distort operate, so we do need to provide shared object support, and we do need to preserve the ABI.
Further, for folks using fltk in plugins (and I understand that there are a few audio plugins that use fltk) you really need to have a fltk DLL that works, or the plugin architectures generally fail...
> Again, look around the other frameworks and toolkits, they all seem to disagree ; light or not.
This is a bit of an odd thing...
I do a lot of multi-threaded code, and a lot of it is cross-platform. And I know quite a lot of engineers who are doing similar work. Pretty much all of them are using some sort of library or abstraction layer to provide portability of code over differing threading API’s, semas, mutexes, queues, whatever.
And in every case I can think of, the lib they are using already provides some sort of timer abstraction. I can’t image they’d even consider using the timer abstractions provided by the GUI lib rather than the timer abstractions in their portability layer...
So it just makes no sense to me to provide that capability in the GUI lib - as far as I can tell, the folks that need that capability are already getting it from another lib dedicated to abstracting those sorts of OS services anyway.
> If we followed that principle, then we should not have any threading api, and what we use internally should be kept internal in terms of threading needs,
Fltk does not have a threading API. What we have is an API that provides a basic mechanism to protect the graphical context (which is not thread safe) from being too badly perturbed in multi-threaded code.
Likening that to a threading API is something of a stretch...
There are libs that do that job well; they should be used to do that job.
Fltk’s job is to do the GUI, not abstract away the entire operating system portability issue.
"'fabien' via fltk.coredev" <fltkc...@googlegroups.com> writes:
> Now meanwhile, I'm thinking that it would be great if we could only use
> c++11 extensions with fltk in near future, did anyone tried this recently ?
And this would render FLTK unusable for old platforms and compilers,
which is the main reason why FLTK is so compelling for some users. That
story was told here numerous times.
Not to say that some of those users (like me), find c++11 and everything
after that, abomination.
>>
> You did not get the point, here we were discussing about _using_ c++11 on
> the top of fltk 1.3.3 and be able to build with it for those who want it,
> then on another thread I confirmed that this is still the case (at least on
> win/mac osx recent toolchains) so the question is closed.
The same can be applies here: imagine there are C++11 features on top of
FLTK that can be turned off. Then someone adds another layer of widgets,
sleep() or whatever functions on top of that. Then suddenly, those C++11
features aren't optional any more.
> which is the main reason why FLTK is so compelling for some users. That
>> story was told here numerous times.
>>
>> Not to say that some of those users (like me), find c++11 and everything
>> after that, abomination.
>>
>> 'Everything' after c+_11 ? it is the latest stable standard for C++ that I
> know of being able, could you be more specific ?
There is a stable revision named C++14 and gcc/clang are already
supporting some of the requirements. And also, there is C++17 with some
known features in preparation.
> simplifying even stl use (again read my previous emails about this).
I think this is subjective matter.
> It contains a lot of concept that were initially developed in the famous
> boost library.
> It addresses a lot of modern development paradigms that c++ implementation
> did not address initially and that are present in dot c sharp language for
> a while already as an example.
Most of those concepts aren't initially developed in Boost, but are
collected from either previous projects (e.g. boost::regex or
Boost.Preprocessor) or are copied from other languages with C++ specific
sugar on top of it.
I think we can talk about this topic all night long, without making a
single step forward or backward. The main questions are: will it make
FLTK faster, ligter or more portable than currently is?