Hi, I'm having problems with pthreads on uClinux(kernel 2.6.x) + Nios2. Sometimes it works, sometimes don't. If I put usleep(); in my application, the system stops, and I have to restart it. When I try without usleep it run, but I have a unfair scheduler. I had tried sched_yield(); but it don't work well. Can someone help me with it? There is other functions that I can use or other thread lib ? There is other way that I can obtain concurrency in Nios2 + uClinux?
Regards, Alexandre Here is my source--------------------------- #include <pthread.h> #include <stdlib.h> #include <stdio.h> #include <linux/sched.h> #include <unistd.h> void writer() { while(1) { printf("Writer!!!!\n"); //sched_yield(); usleep(1); } printf("Writer end!\n"); } void reader() { while(1) { printf("Reader!!!!\n"); //sched_yield(); usleep(1); } printf("Reader end!\n"); } int main() { pthread_t thread; int rc = pthread_create(&thread, NULL, (void *)writer, NULL); if (rc){ printf("ERROR; [writer] return code from pthread_create() is %d\n", rc); exit(-1); } rc = pthread_create(&thread, NULL, (void *)reader, NULL); if (rc){ printf("ERROR; [reader] return code from pthread_create() is %d\n", rc); exit(-1); } usleep(8000000); //pthread_join(threads[0],NULL); return 0; } ----------------------------------------
_______________________________________________ uClinux-dev mailing list uClinux-dev@uclinux.org http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by uclinux-dev@uclinux.org To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev