|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
Help with pthread_create not returning
Hi, in the LCDproc project we have a driver which uses pthread_create to spin off a new thread. For a reason I don't understand, that call does never return neither success nor any error.
Even threading code that does work well as a standalone program does not work when copied into the driver. The file in question can be found here: http://lcdproc.cvs.sourceforge.net/viewvc/lcdproc/lcdproc/server/drivers/lis.c The thread's start_routine is at line 290 (lis_read_thread) and the thread creation is at line 514, copied here for reference (but please look at the complete file linked to above): Code:
int lis_read_thread(void *arg) { Driver *drvthis; PrivateData *p; char unsigned buffer[64]; int size; drvthis = (Driver *)arg; p = (PrivateData *) drvthis->private_data; while(! p->child_flag) { for (size = ftdi_read_data(&p->ftdic, buffer, 64); size > 0; size = ftdi_read_data(&p->ftdic, buffer, 64)) ; if (size < 0) { p->parent_flag = 0; return size; } } p->parent_flag = 0; return 0; } // Later in init... // create a thread to keep a read up on the device err = pthread_create( &read_thread, NULL, (void *) lis_read_thread, drvthis ); if (err) { report(RPT_ERR, "%s: pthread_create() - %s", drvthis->name, strerror(err)); goto err_framebuf; } report(RPT_INFO, "%s: read thread created"); p->parent_flag = 1; // show we're now a happy parent, birth successful. Please, have a look at it and help us getting this to work on FreeBSD. Thank you! Edit: System is FreeBSD 7.3-RELEASE. Last edited by Darwimy; 15th December 2010 at 08:05 PM. |
|
|||
Additional information: Here is the output from a gdb debug session.
Code:
root@kirika:lcdproc-anon# gdb server/LCDd GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-marcel-freebsd"... (gdb) b lis.c:514 No source file named lis.c. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (lis.c:514) pending. (gdb) run -c ./LCDd.conf -r 4 -f Starting program: /usr/home/mmd/devel/lcdproc-anon/server/LCDd -c ./LCDd.conf -r 4 -f LCDd version 0.5dev starting Built on Dec 16 2010, protocol version 0.3, API version 0.5 Using Configuration File: ./LCDd.conf Set report level to 4, output to stderr LCDd 0.5dev, LCDproc Protocol 0.3 Part of the LCDproc suite Copyright (C) 1998-2010 William Ferrell, Scott Scriven and many other contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Server running in foreground Listening for queries on 127.0.0.1:13666 [New LWP 100112] Breakpoint 2 at 0x281ad394: file lis.c, line 514. Pending breakpoint "lis.c:514" resolved [New Thread 0x28213040 (LWP 100112)] [Switching to Thread 0x28213040 (LWP 100112)] Breakpoint 2, lis_init (drvthis=0x28211060) at lis.c:514 514 err = pthread_create( &read_thread, (gdb) s ^C <<<< Here I pressed Ctrl-C because program hang Program received signal SIGINT, Interrupt. 0x281ce215 in __error () from /lib/libthr.so.3 (gdb) bt #0 0x281ce215 in __error () from /lib/libthr.so.3 #1 0x281ce02b in __error () from /lib/libthr.so.3 #2 0x281d0d20 in _thread_state_running () from /lib/libthr.so.3 #3 0x00000011 in ?? () #4 0x00000000 in ?? () #5 0x00000000 in ?? () #6 0x00000000 in ?? () #7 0xbfbfe804 in ?? () #8 0x28069d29 in _rtld_error () from /libexec/ld-elf.so.1 #9 0x281c87c7 in pthread_mutex_getyieldloops_np () from /lib/libthr.so.3 #10 0x00018710 in ?? () #11 0x28097400 in ?? () #12 0x00018710 in ?? () #13 0x28097800 in ?? () #14 0x28097a00 in ?? () #15 0x280960e4 in ?? () #16 0x281cfbcc in ?? () from /lib/libthr.so.3 #17 0x00000000 in ?? () #18 0x28213040 in ?? () #19 0xbfbfe7d8 in ?? () #20 0x281c90fb in pthread_mutex_trylock () from /lib/libthr.so.3 Previous frame inner to this frame (corrupt stack?) (gdb) (gdb) kill Kill the program being debugged? (y or n) y |
Thread Tools | |
Display Modes | |
|
|