How to use -Mchkstk with a pthread program in Linux?

HI,

I am trying to use -Mchkstk to compile a pthread program. However, it prints an stack overflow message and then exits the program.

Error: in routine foo there is a
stack overflow: thread 0, max 8180KB, used 1KB, request 64B

i.e. max is 8MB and the request is only 64 bytes. How could stack overflow happen?

Based on the message, I don’t understand why there is a stack overflow. I searched various documentation, faq, google and I cannot find an answer.

May be I did not compile the program with the proper flags.
I used the following (and other variations):

pgcc -mp -Mchkstk -lpthread -o a a.c
pgcc -Mchkstk -lpthread -o a a.c

They all printed stack overflow.

My test program is pretty simple:


#include <pthread.h>
#include <stdio.h>

static void* foo(void* inp);

int main (
int argc,
char* argv)
{
pthread_t pt;
pthread_attr_t attr;
void* rv;

pthread_attr_init (&attr);
pthread_attr_setstacksize (&attr, 1024 * 64);

fprintf (stderr, “%s %d\n”, FILE, LINE);
if (pthread_create (&pt, (void*)&attr, foo, NULL) == 0)
{
pthread_join (pt, &rv);
printf (“rv=%p\n”, rv);
}
fprintf (stderr, “%s %d\n”, FILE, LINE);

return 0;
}


static void* foo (void* inp)
{
char table_name[64];

strcpy (table_name, “dk3djfdlkjfldsjfldkfdsf”);
fprintf (stderr, “%s %d %s\n”, FILE, LINE, table_name);
return 0;
}

pgcc --version
pgcc 13.9-0 64-bit target on x86-64 Linux -tp p7
The Portland Group - PGI Compilers and Tools
Copyright © 2013, NVIDIA CORPORATION. All rights reserved.

Does -Mchkstk work with pthread at all?
If it does, how do I make the above program to run?

Thanks.

Hi gman168,


I sent this on to engineering for a better understanding on what’s happening. I’ll post as I know more.

  • Mat

Thank you, Mat.

Hi gman168,

I talked with our compiler architect about this. “-Mchkstk” was never intended for use with pthreads so not a supported feature.

Sorry,
Mat

Thanks.

It is the message that was confusing. It would be less confusing if it prints something like “-Mchkstk with pthread is not supported”. A warning/limitation in the documentation would even be better. If that was the case, I would not spend time to investigate how to make it works.