Forum Discussion
Altera_Forum
Honored Contributor
21 years agoHas anyone else had problems with POSIX threads?
Hi
I have made an app with 2 POSIX threads for my linux kernel(2.6 microtronix). When I establish my 2pthread_t varibles the kernel simply reboots. The uClibC has built in support for POSIX threads, so I don't really understand why it has problems with establishing these varibles(I don't even create the threads). Regards GreateWhite.DK23 Replies
- Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
I compiled your app (with my change) and ran it on one of Altera's board. It worked fine. For the JTAG problem, it is new to me. If you take jtag as the console, you have to start the nios2-terminal on your PC to read from the jtag, so that the kernel won't get stuck during the booting. I don't know what you changed to make the kernel continue without nios2-terminal reading from the jtag. Anyway, for the time being, you can switch to uart as the console: Device drivers --> Character devices --> Serial drivers --> enable Nios serial support, and enable support for console on Nios UART. disbale altera jtag uart support. Regards, wentao - Altera_Forum
Honored Contributor
Hi Wentao
Thx for all your effort. When you ran the program did you do it on a Linux kernel like me??? I use the prebuilt linux project that ships with the Quartus II(linux_1c20.ptf) I use the default setup of the kernel(have only changed it from stratix to cyclone support). Regards GreateWhite.DK - Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
I was using a kernel locally built, but from the same source code. The problem you had with the jtag is still confusing for me. I am quite sure the kernel wont continue during the booting if nios2-terminal is not reading from it. Can you give me more information regarding this issue? maybe we can find some clue from it. BTW, when you are linking your app, which libraries did you use? Here is the Makefile I was using for your app: <div class='quotetop'>QUOTE </div> --- Quote Start --- include ../../Rules.mak all: test.flt test.gdb clean: rm -f *.[iods] core *.flt *.bin *.elf *.gdb[/b] --- Quote End --- Regards, wentao - Altera_Forum
Honored Contributor
Hi again
Do you have an Email adr I can use??? Perhaps you have messenger (under my profile my MSN name can be found). Then I can send you my hole project. That would perhaps be a more fast and easy way to do it? It is not easy for me to figure out what could be some important fact that you could use. Keep in mind I am quit new at this http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/rolleyes.gif Regards GreateWhite.DK - Altera_Forum
Honored Contributor
Hi Wentao and others
<div class='quotetop'>QUOTE </div> --- Quote Start --- BTW, when you are linking your app, which libraries did you use?[/b] --- Quote End --- I use the ones that the microtronix tool include when the project is created(I guess the uClibc). It is a kernel built entirely from what the quickstart guide from microtronix describe. <div class='quotetop'>QUOTE </div> --- Quote Start --- I was using a kernel locally built, but from the same source code. The problem you had with the jtag is still confusing for me. I am quite sure the kernel wont continue during the booting if nios2-terminal is not reading from it. Can you give me more information regarding this issue? maybe we can find some clue from it.[/b] --- Quote End --- If I don't connect to the dev board at all during boot, the LEDs will not begin there binary count. BUT if I am connected for a second or so and then disconnect(the boot is not done), the kernel boots just fine and will begin the binary count. I think there must be some sort of write buffer in the JTAG interface. As long as this buffer is not full the program can keep running. But once the buffer is full it locks up the intire kernel. Regards GreateWhite.DK - Altera_Forum
Honored Contributor
Hi GreateWhite,
Can you post your app Makefile here? Just want to make sure you are using uClibc. The JTAG problem you observed is normal. You can switch to UART as the console. Regards, wentao - Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
I was meaning the application makefile. But it is too small to bear any information. Can you give me the source code of hello_world.c, I mean the one that can pass compiling without modification? The last one you gave me needed several modifications before it could be compiled. Regards, wentao - Altera_Forum
Honored Contributor
Hi Greatwhite
After performing the modifications that Wentao provided to your application, I was able to compile and run your app under Nios II Linux for a Cyclone 1c12 device. I'd like to give your pthread code a run for its money as well but your code seems to be missing some declarations for the the tmp, thread1, and thread2 variables. Since my knowledge of pthreads is limited, could you post an example that will compile? WRT to the JTAG console issues, are you running into similar problems using a UART console as Wentao suggested? - Altera_Forum
Honored Contributor
Hi Ken/Wentao
Here below is the code I use. I have noticed that the kernel also reboots if I call the func "pthread_attr_getstacksize(&attr, &stacksize);" The "pthread_attr_init(&attr);" called before the "pthread_attr_getstacksize" call apperently gets called correct. I have modified the "pthread_create" function a bit(have made alot of printf's). But all these printf's don't get printed(have usleep(1000000) after each printf so they have time to get printed) I am thinking this might be a memory problem. Perhaps something is not allocated as it should be, but I am not sure.
Regards GreateWhite.DK#include <stdio.h># include <stdlib.h># include <pthread.h># include <unistd.h> void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); return (NULL); } int main() { pthread_t thread1, thread2; pthread_attr_t attr; size_t stacksize; char *message1 = "Thread 1"; char *message2 = "Thread 2"; int iret1, iret2; //Will try to allocate some memory to see if this is possible void **newstack; printf("\n##################################\n"); printf("Will now allocate 8096 bytes\n"); newstack = (void **) malloc(8096); printf("\n**********************************\n"); printf("8096 bytes allocated\n"); //Just give some time to the UART to printf the messages. usleep(1000000); /* Create independant threads each of which will execute function */ printf("Will now create threads!!!\n"); //Just give some time to the UART to printf the messages. usleep(1000000); //Attributes for the thread. pthread_attr_init(&attr); printf("1!\n"); //Just give some time to the UART to printf the messages. usleep(1000000); //Get the stacksize of the thread. //pthread_attr_getstacksize(&attr, &stacksize); //printf("Stacksize = %d\n", stacksize); //Just give some time to the UART to printf the messages. usleep(1000000); //Setting the stack size //pthread_attr_setstacksize(&attr, 1000); //Creating the thread. pthread_create(&thread1, &attr, print_message_function, (void *)message1); //iret1 = pthread_create( &thread1, NULL, print_message_function, NULL); printf("Thread One created!!!\n"); //Just give some time to the UART to printf the messages. usleep(1000000); //Creating a thread with standard attributes "NULL" iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); return 1; } - Altera_Forum
Honored Contributor
Hey Greatwhite
I've noticed the same problem on my end... it'll print the number 1 but won't go any further than that. I don't know how much more time I can sink into this at the moment but my current suggestion would be to try building a filesystem project with the sample-threads package. Alternatively, just upload the 7 executables (ex1..ex7) to your uClinux system. The sample-threads package contains 7 executables to test the pthread capabilities of uClibc (Wentao can correct me on this if I'm wrong). If they run properly, you can take a peek at the source code for them in ...altera/kits/nios2/examples/software/linux/apps/samples/thread If they don't run properly then there's a potential problem in your hardware or kernel... hopefully we can narrow this down a bit... Let me know how it goes