Operating System - HP-UX
1820890 Members
3911 Online
109628 Solutions
New Discussion юеВ

Bus error in thread program

 
SOLVED
Go to solution
Sung-hee Kim
Occasional Contributor

Bus error in thread program

Hi,

The following is simple thread program. But it receives Bus erorr and creates core.

#include
#include

#define THREAD_NUM 1
#define MAX_STRING_SIZE 64 * 1024

void* foo(void* arg) {
char data[MAX_STRING_SIZE];

bzero(data, sizeof(data));
return;
}

int main() {
int i;
pthread_t threadId[16];

if (THREAD_NUM > 0) {
for (i = 0; i < THREAD_NUM; i++)
pthread_create(&threadId[i], NULL, foo, NULL);

for (i = 0; i < THREAD_NUM; i++)
pthread_join(threadId[i], NULL);
}
else
foo(NULL);
}

When I decrese MAX_STRING_SIZE to 32K or run without thread, it runs successfully. How do you think I could resolve this?

Thanks in advance.
5 REPLIES 5
Steve Steel
Honored Contributor

Re: Bus error in thread program

Hi

Would help to know
1)OS
2)Compiler Version
3)Patch Level - Certainly shells and libs
4)Compile options.
5)The output of
file core
on one of the core files generated and the
exacr=t bus error.

However looking in the latest C++ patches I find

increase maximum string literal length from
8 to 32K

You are probably hitting that.


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Sung-hee Kim
Occasional Contributor

Re: Bus error in thread program

The excution environment is the follwing.

1)OS: HP-UX 11.0
2)Compiler Version: B.11.01.20(C/ANSI C Developer's Bundle for HP-UX 11.00)
3)Patch Level
- B.11.00.53.2 HP-UX General Release Patches, June 2001
- B.11.00.51.2 HP-UX Hardware Enablement and Critical Patches, December 2000
4)Compile options.
cc -o thr thr.c -lpthread
Steve Steel
Honored Contributor

Re: Bus error in thread program

Hi

If you are missing any of these patches add them

hp-ux_patches/s700_800/11.X/PHSS_25171
hp-ux_patches/s700_800/11.X/PHSS_25249
hp-ux_patches/s700_800/11.X/PHCO_25707
hp-ux_patches/s700_800/11.X/PHCO_23963
hp-ux_patches/s700_800/11.X/PHKL_18543
hp-ux_patches/s700_800/11.X/PHCO_23651
hp-ux_patches/s700_800/11.X/PHCO_21187
hp-ux_patches/s700_800/11.X/PHKL_24116
hp-ux_patches/s700_800/11.X/PHKL_24027
hp-ux_patches/s700_800/11.X/PHKL_20016
hp-ux_patches/s700_800/11.X/PHKL_22589
hp-ux_patches/s700_800/11.X/PHKL_23226
hp-ux_patches/s700_800/11.X/PHKL_22677
hp-ux_patches/s700_800/11.X/PHSS_24381
hp-ux_patches/s700_800/11.X/PHSS_24832
hp-ux_patches/s700_800/11.X/PHSS_24301
hp-ux_patches/s700_800/11.X/PHSS_24303


Also

What is the exact bus error and the output
of file core

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Sung-hee Kim
Occasional Contributor

Re: Bus error in thread program

Thanks the replies.

The output of "> file core" is

core: core file from 'thr'

But I don't know what "exact bus error" is.
Steven Gillard_2
Honored Contributor
Solution

Re: Bus error in thread program

You've hit the default thread stack size limit, which is 64k as shown by the following program:

#include
#include
int main() {
size_t stacksize;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &stacksize);
printf("stacksize = %d\n", stacksize);
}

$ gcc thrstack.c -o thrstack -lpthread
$ ./thrstack
stacksize = 65536

- allocate memory off the heap with malloc() instead of using the stack.

- change the default thread stack size attribute with pthread_attr_setstacksize(). Refer to the man page for details.

Regards,
Steve