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
Think that I might be having some problems with my memory control in the kernel. So it's not a POSIX thing. I have the same problem if I establish a array of 1000 int's.
GreateWhite.DK - Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
I am not sure where you put the 4k array. If it is on the stack, you have to make sure your stack is big enough (you can use flthdr to check the size of the stack for an application). wentao - Altera_Forum
Honored Contributor
Hi wentao
Thx for your answer. I have tried making my stack for my app 12K big. I used the "elf2flt -s 12000" command. I could not find the "flthdr" command that you mentioned in the elf tools. The kernel still reboots when I try to start my app. The stacksize I changed was the APP's and not the kernel's. Should it be the kernels(if yes how can this be done)??? <div class='quotetop'>QUOTE </div> --- Quote Start --- I am not sure where you put the 4k array[/b] --- Quote End --- Can/should I control this myself? Regards GreateWhite.DK - Altera_Forum
Honored Contributor
12k is not actually big (depending how complex your application is). Can you try 32k? The size of the kernel stack is fixed (2 pages, around 8k), and I dont think it is the cause of your problem. flthdr is a utility to check the flat header information generated by elf2flt. Since you know how to set the stack size, you don't have to find it. <div class='quotetop'>QUOTE </div> --- Quote Start --- Can/should I control this myself?[/b] --- Quote End --- if you declare this array as a global or static variable, it is on the heap, not on the stack. but if you declare it as a automatic variable, it is on the stack. Regards, wentao - Altera_Forum
Honored Contributor
Hi wentao
I have now tried with 32K. That did not do the trick sadly. <div class='quotetop'>QUOTE </div> --- Quote Start --- if you declare this array as a global or static variable, it is on the heap, not on the stack. but if you declare it as a automatic variable, it is on the stack.[/b] --- Quote End --- I declare it as a variable. Best regards GreateWhite.DK - Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
It sounds like my guess is not true. Let me try to understand the problem: your application restarts the system with the big array somewhere, but will not once the array is removed. Is this true? Still don't know where your array is: <div class='quotetop'>QUOTE </div> --- Quote Start --- I declare it as a variable.[/b] --- Quote End --- It is global, static or automatic? But this is not important now. Best regards, wentao - Altera_Forum
Honored Contributor
Here is my code then you can see it all.
When I create the arrayBuffer the kernel panics. The IDE does not allow debugging of this app since it's a app in the filesystem of the kernel. Normally I would just debug it I find the error this way. If I don't create the array the kernel runs just fine. Hope that this clarifies your question. Regards GreateWhite.DK#include <stdio.h># include <unistd.h># include <stdlib.h># include <pthread.h> void *print_message_function( void *ptr ); int main() { printf("NIOS II says hello\n"); int *arrayBuffer; for(int x=0; x < 10; x++) { arrayBuffer = new int; printf("*\n"); } //pthread_t tmp; //pthread_t thread2; char *message1 = "Thread 1"; printf("2\n"); char *message2 = "Thread 2"; int iret1, iret2; printf("#\n"); /* Create independant threads each of which will execute function */ //iret1 = pthread_create( &tmp, NULL, print_message_function, (void*) message1); //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); return 1; } void *print_message_function( void *ptr ) { printf("***\n"); char *message; message = (char *) ptr; while(1) { printf("%s \n", message); usleep(1000000); } } - Altera_Forum
Honored Contributor
Hi GreateWhite.DK,
Now I am interested to see how you compiled this program. I don't think you can use "new" here: <div class='quotetop'>QUOTE </div> --- Quote Start --- for(int x=0; x < 10; x++) { arrayBuffer[x] = new int[10]; printf("*\n"); }[/b] --- Quote End --- I would do it this way: int x; for(x=0; x < 10; x++) { arrayBuffer[x] = malloc (sizeof(int) * 10); printf("*\n"); } Since the memory are malloced from the heap, the problem is not a stack size issue. I think "new" caused your problem. Regards, wentao - Altera_Forum
Honored Contributor
Hey GreatWhite,
Actually, the IDE does provide rudimentary debugging. Take a peek at the Reference Guide included with the Nios II Linux Distribution. It wasn't easy coaxing the IDE debugger to work with Linux apps so the process isn't perfect but it's a start. If the Nios II IDE starts behaving oddly while debugging Linux applications, let me know, it is still possible to debug using Insight or the GDB commandline as well. - Altera_Forum
Honored Contributor
Hi Wentao, ken and others
Wentao : Have tried with malloc same old problem still. Something new I have noticed is when I terminate my nios2-terminal app the kernel boots just fine(I think). I say this because the LEDs begins the binary count. The second I connect to the board again the kernel reboots!!! The kernel just keeps on rebooting while I'm connected. The second I then disconnect the binary count on the LEDs begins again. Very strange I think. Some ideas??? How do I change the microtronix linux kernel so that it uses the serial IF as printf instead of the JTAG. Regards GreateWhite.DK