Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Problems with pthreds

Altera_Forum
Honored Contributor II
1,434 Views

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); 

}
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
634 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
634 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
634 Views

can you post your Makefile for this program?

0 Kudos
Altera_Forum
Honored Contributor II
634 Views

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 &#39;$(DEBUG)&#39; &#39;1&#39; 

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
0 Kudos
Altera_Forum
Honored Contributor II
634 Views

Add this to your Makefile, check and make sure -lpthread appears before -lc. 

LDLIBS:=-lpthread $(LDLIBS)
0 Kudos
Reply