Threads

Vilmos NEBEHAJ vnebehaj at mail.ahiv.hu
Mon Sep 29 12:22:40 PDT 2003


On Mon, Sep 29, 2003 at 07:52:27PM +0300, Stefan Chekanov wrote:
> I am developing an application for FreeBSD that utilizes multiple threads.
> It works fine, except that after some minutes of work most of the threads
> suddenly stop.
> 
> I have examined the stack and found that most of the threads have this stack
> #0 ... in _thread_kern_sched() from /usr/lib/libc_r.so.4
> #1 ... in _thread_kern_sched_state() from /usr/lib/libc_r.so.4
> #2 ... in _thread_fd_lock_debug() from /usr/lib/libc_r.so.4
> #3 ... in _close() from /usr/lib/libc_r.so.4
> #4 ... in _res_close() from /usr/lib/libc_r.so.4
> #5 ... in res_send() from /usr/lib/libc_r.so.4
> #6 ... in res_query() from /usr/lib/libc_r.so.4
> #7 ... in res_querydomain() from /usr/lib/libc_r.so.4
> #8 ... in res_search() from /usr/lib/libc_r.so.4
> #9 ... in _gethostbydnsname() from /usr/lib/libc_r.so.4
> #10 ... in gethostbyname2() from /usr/lib/libc_r.so.4
> #11 ... in gethostbyname() from /usr/lib/libc_r.so.4
> 
> and one trhead with this stack
> 
> #0 ... in _thread_sys_poll() from /usr/lib/libc_r.so.4
> #1 ... in _thread_kern_sched_state_unlock() from /usr/lib/libc_r.so.4
> #2 ... in _thread_kern_scheduler() from /usr/lib/libc_r.so.4
> #3 0x0 in ??()
> 
> Does anybody have an idea what might cause threads to stop?
> Is it possible that sockets library is not threads safe?
> Especially the part that is used to resolve hostnames?

gethostbyname() is not threadsafe, don't use it in threaded apps
(or protect it with a mutex).

-- 
[vili]


More information about the freebsd-threads mailing list