[ntp:hackers] Using Posix API's to simplify do_resolve_internal()
Philip Prindeville
philipp_subx at redfish-solutions.com
Fri Jun 7 05:10:24 UTC 2013
On Jun 6, 2013, at 9:42 PM, Terje Mathisen <terje at tmsw.no> wrote:
> Philip Prindeville wrote:
>> I'm looking at the way that do_resolve_internal() works, and it seems
>> that it could be a lot more lightweight (and more friendly to
>> embedded systems).
>>
>> Using fork() and pipe() seems very 1980's. ;-)
>>
>> Why not, instead, use a pthread_create() to have a worker thread that
>> looks at a (mutex-protected) list of names to resolve?
>>
>> We could use getaddrinfo() which is POSIX-compliant and reentrant, so
>> inherently callable safely from inside a pthread.
>>
>> Just a thought…
>
> You are definitely not the first to have that particular thought. :-)
>
> The reason ntpd doesn't use pthreads at all is simply that ntpd still compiles on several platforms that simply don't have pthreads, i.e. fork() is, as you say, very 1980.
>
> Even mutex might limit portability. :-(
>
> I've written a multi-threaded version of ntpd for linux, this compiled as-is on both 32 and 64-bit FreeBSD as well, but required custom handling on Win*.
>
> Terje
>
> --
Could you share that code? It would be handy in embedded Linux, QNX, VxWorks, etc. and similar environments.
Thanks,
-Philip
More information about the hackers
mailing list