vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I've got a code, that looks a little like this: #define MAXNAME 20 #define MAXPACKET 20000 struct package_info { unsigned short transport_id; char filename[MAXNAME]; time_t modified; }; struct segment_header { unsigned short transport_id; unsigned short size; unsigned int segm_num; }; struct segment { struct segment_header header; unsigned char buffer[MAXPACKET - sizeof(struct segment_header)]; }; There is also a class: class C { public: int do_sth(int sd) { segment segm; // HERE (explained later) // do some stuff }; static void* fun(void* arg) { C *pc = (C*)arg; pc->do_sth(6); }; run() { pthread_create(... fun, this); } }; And in main() there is code resembling this: int main() { C c; c.run(); // wait for c to stop } When line "pc->do_sth(6)" is executed, my thread is signaled with SIGBUS. Removing line with comment "HERE" causes the program to run smoothly, although it can't do anything useful without it. I use: # g++ -v Reading specs from /usr/local/lib/gcc/hppa2.0w-hp-hpux11.11/3.4.1/specs Configured with: /scratch/zack/pkgbuild/3.3.1/hpux-11/gcc-3.4.1/configure --enable-languages= c,c++ --enable-threads=posix --disable-nls --with-gnu-as --without-gnu-ld -- with-as=/usr/local/bin/as --with-ld=/usr/ccs/bin/ld --with-libiconv-prefix=/ usr/local --prefix=/usr/local Thread model: posix gcc version 3.4.1 and compile with: g++ -Wall -pedantic -o mcast -g3 *.cpp -pthread Under gdb I've got the following error: Program received signal SIGBUS, Bus error. 0x00003440 in CDeplClient::segm_receive(int) (this=0x40005cd0, sd=0) at deplclient.cpp:126 126 { (gdb) If I'll insert line "segment segm;" into any other method, this method instantly causes SIGBUS. Any ideas what I am doing wrong? TIA, JD |
| |||
| "jd" <jedrzej_dudkiewicz@poczta.interia.pl> writes: > int do_sth(int sd) > { > segment segm; // HERE (explained later) The sizeof(segm) is 20000, that's not so big as to cause the thread to run out of stack, unless you specified extremely small default stack at pthread_create() time. > pthread_create(... fun, this); Perhaps the problem hides in the '...' above. Post a minimal compilable test case, and your error will be revealed. Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
| |||
| > > int do_sth(int sd) > > { > > segment segm; // HERE (explained later) > > The sizeof(segm) is 20000, that's not so big as to cause the thread > to run out of stack, unless you specified extremely small default > stack at pthread_create() time. Actualy this was enough to run out of stack - there was about 50kB of data on the stack already which I missed, both when I was preparing sample code and looking through original one while trying to found a bug. Well, gotta go, got a lot of things to learn Thanks for help! JD PS I was thinking that it can be the case (too much data on stack), but then I thought, that it would rise SIGSEGV... Wrong |
| ||||
| Possibly an alignment error. Try unioning a double over the segment header to force 8-byte alignment, and see what happens. dk "jd" <jedrzej_dudkiewicz@poczta.interia.pl> wrote in message news:ctqqci$u2n$1@news.supermedia.pl... > I've got a code, that looks a little like this: > > #define MAXNAME 20 > #define MAXPACKET 20000 > > struct package_info > { > unsigned short transport_id; > char filename[MAXNAME]; > time_t modified; > }; > > struct segment_header > { > unsigned short transport_id; > unsigned short size; > unsigned int segm_num; > }; > > struct segment > { > struct segment_header header; > unsigned char buffer[MAXPACKET - sizeof(struct segment_header)]; > }; > > There is also a class: > > class C { > public: > int do_sth(int sd) > { > segment segm; // HERE (explained later) > // do some stuff > }; > static void* fun(void* arg) > { > C *pc = (C*)arg; > pc->do_sth(6); > }; > run() > { > pthread_create(... fun, this); > } > }; > > And in main() there is code resembling this: > > int main() > { > C c; > c.run(); > // wait for c to stop > } > > When line "pc->do_sth(6)" is executed, my thread is signaled with SIGBUS. > Removing line with comment "HERE" causes the program to run smoothly, > although it can't do anything useful without it. > > I use: > # g++ -v > Reading specs from /usr/local/lib/gcc/hppa2.0w-hp-hpux11.11/3.4.1/specs > Configured with: > /scratch/zack/pkgbuild/3.3.1/hpux-11/gcc-3.4.1/configure --enable-languages= > c,c++ --enable-threads=posix --disable-nls --with-gnu-as --without-gnu-ld -- > with-as=/usr/local/bin/as --with-ld=/usr/ccs/bin/ld --with-libiconv-prefix=/ > usr/local --prefix=/usr/local > Thread model: posix > gcc version 3.4.1 > > and compile with: > > g++ -Wall -pedantic -o mcast -g3 *.cpp -pthread > > Under gdb I've got the following error: > > Program received signal SIGBUS, Bus error. > 0x00003440 in CDeplClient::segm_receive(int) (this=0x40005cd0, sd=0) > at deplclient.cpp:126 > 126 { > (gdb) > > If I'll insert line "segment segm;" into any other method, this method > instantly causes SIGBUS. > > Any ideas what I am doing wrong? > > TIA, > > JD > > |