The first step is to try to run the function without entering threads. Just write a .c file that has main , which does a minimum to get ready to start the thread, and then instead it just calls the function. It is easier to debug if you can recreate the problem with just one thread.
In addition, if you are using gcc, you must compile with:
-fstack-protector-all -Wstack-protector -fno-omit-frame-pointer
in addition to your normal flags (at least until you find the problem). This will help with debugging and may give more warnings at compile time. I assume that you know how the -O flags can affect debugging ability and functionality (especially if you are already doing something wrong or undefined in C code).
When you are in GDB and everything looks like they are locked or the program takes a long time to do something, you can usually press CTRL Z to return to (gdb) without killing the program. This gives a stop signal to the program and allows you to interact again with GDB so that you can find out what the program actually does.
Edit
I, apparently, solved the problem in discussing comments, so I will write what the problem is.
A quick look at the code does not indicate a problem that would lead to a segmentation error (access to illegal memory), and Zypsy (OP) told me that the function works fine when called directly from the main, and not in a run through a separate thread.
Valgrind reported that the thread stack space could not be expanded to a specific address. On Linux, the main thread stack is mapped to the application in such a way that it can grow easily, but this often fails when memory is allocated for thread stacks.
I asked Zypsy (OP) to insert some code that will output the address of what is known to be low on the thread stack ( printf("thread stk = %p\n", &input); ) so that this value can be compared with the address indicated in the error message, From this I could guess the size of the stack. This did not suggest that between the start of the stream function and its failure a lot of stack space was spent, but the space also did not seem too small for the code in question (it apparently turned out to be too small).
Since the pthread_create function allows you to either accept the attributes of the thread (pass to NULL ) or pass an argument defining the various parameters for the thread, which I asked if the code that called pthread_create could be published, so that I could see if there were any suspicious settings.
After looking at this code, it (an application-specific shell for various pthread_ functions), I saw that some attributes related to the stack were actually set. I asked the OP to look at the calls to this function and look at suspicious things related to how the stack was allocated (make sure that the size value and the size of the allocated memory actually match). It turned out that the OP found that this stack stream is allocated less than the stacks of other threads. The stack was too small.