Altera_Forum
Honored Contributor
15 years agoPthread_create hangs program
Hi,
I'm trying to compile some C++ code that uses pthread on uClinux. I'm using this toolchain: http://www.nioswiki.com/index.php?title=OperatingSystems/UClinux/BinaryToolchain I can compile C++ code just fine, but whenever I try to use pthreads, the program will hang at the pthread_create () call. At this point I'm just trying to compile a very simple program. It will hange right at the create call and never exit. In addition, I get a linker error when trying to use pthread_join.
# include <iostream># include <pthread.h># include <unistd.h>
void *ReadMessagesThread(void *ptr);
int main(int argc, char** argv)
{
using namespace std;
pthread_t thread;
cout << "starting pthread..." << endl;
int rc = pthread_create(&thread, NULL, ReadMessagesThread, NULL);
cout << "return value is : " << rc << endl;
//pthread_join(thread, NULL);
return 0;
}
void *ReadMessagesThread(void *ptr)
{
using namespace std;
for (int i = 0; i < 5; i++)
{
cout << "In thread : " << i << endl;
}
}
Here is the MakeFile I'm using:
PROJ_NAME = remoteModelServer
CXX=nios2-linux-uclibc-g++
LDLIBS:=-lpthread $(LDLIBS)
CFLAGS=-O2 -fno-gnu-keywords
LDFLAGS=-Wl,-elf2flt
$(PROJ_NAME): *.cpp
$(CXX) $(LDLIBS) $(CFLAGS) $(LDFLAGS) -o $(PROJ_NAME).exe *.cpp
.PHONY: clean
clean:
-rm -f *. *.elf *.gdb *.bin *.exe *.flt
Any ideas what I could be doing wrong? Thanks