Forum Discussion
Altera_Forum
Honored Contributor
21 years agoProblems with pthreds
I'm a program benchmark with pthreads, but I'm having really problems with it. Now i'm only want to do a simple hello world, but when I execute it the uClinux reinit another time. Can someone help me please? Can put some example that really run? Thanks to all.
# include <stdio.h># include <unistd.h># include <stdlib.h># include <pthread.h># include <sched.h># include <errno.h> void print_message_function( void ){ char message = "Hello"; printf("%s ", message); pthread_exit(NULL); } void main (int argc, char *argv[]){ pthread_t thread1, thread2; //char *message1 = "Hello"; //char *message2 = "World"; //pthread_attr_t pthread_attr_default; printf("\nThread 1"); pthread_create( &thread1, NULL, (void*)&print_message_function, NULL); printf("\nThread 2"); pthread_create( &thread2, NULL, (void*)&print_message_function, NULL); pthread_exit(NULL); exit(0); }5 Replies
- Altera_Forum
Honored Contributor
Hi Guillemn,
Try these changes: <div class='quotetop'>QUOTE </div> --- Quote Start --- /*void print_message_function( void ){*/ void print_message_function (void *arg){ char message = "Hello"; printf("%s ", message); pthread_exit(NULL); } void main (int argc, char *argv[]){ pthread_t thread1, thread2; //char *message1 = "Hello"; //char *message2 = "World"; //pthread_attr_t pthread_attr_default; printf("\nThread 1"); pthread_create( &thread1, NULL, (void*)&print_message_function, NULL); printf("\nThread 2"); pthread_create( &thread2, NULL, (void*)&print_message_function, NULL); /*pthread_exit(NULL);*/ /* Wait for threads to exit before trashing the pthread_t vars (on stack)*/ pthread_join (thread1, NULL); pthread_join (thread2, NULL); exit(0); }[/b] --- Quote End --- Regards, --Scott - Altera_Forum
Honored Contributor
Hello, I compiled another time the file corrected, but the both files can be compiled perfectly, without warning and it can be put in uClinux. But when starts the both execution, the system renicialize every time.
Can it be a problem with a uClinux configuration? what I can do?? Thanks, Guillem - Altera_Forum
Honored Contributor
can you post your Makefile for this program?
- Altera_Forum
Honored Contributor
include Rules.mak
# # configurable options# - set DEBUG = 1 to turn on debugging support# DEBUG = 0 PROJ_NAME = threads INSTALL_DIR = PROGS := $(PROJ_NAME).exe CFLAGS += # # You should not need to modify anything beyond this point# ifeq '$(DEBUG)' '1' CFLAGS += -O0 -g PROGS += $(PROGS:.exe=.gdb) endif all: $(PROGS) threads.bin: threads.o .PHONY: clean clean: -rm -f *.[oad] *.elf *.gdb *.bin *.exe .PHONY: install install: all ifeq "$(INSTALL_DIR)" "" $(error No installation directory specified) endif mkdir -p $(INSTALL_DIR)/bin install -v $(filter %.exe, $(PROGS)) $(INSTALL_DIR)/bin this is the Makefile, do you need the rules.mak too? thanks for all, Guillem - Altera_Forum
Honored Contributor
Add this to your Makefile, check and make sure -lpthread appears before -lc.
LDLIBS:=-lpthread $(LDLIBS)