Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a rather complex and interesting problem here, maybe somebody has run across this before:
I have an application running on an embedded ARM (in the chip we build). I've written a test application that will setup 2 threads (with priority) along with moving the "main" thread to a different priority (> 0). This test application runs just fine, compiled on the board or using cross tools. The Linux kernel is a 2.4.20 flavor.
This same logic is then moved into a library (.so) and I have the "real" application linking this .so. When this "real" application runs, when I get to the point of spawning the first thread (an ISR thread), the thread gets created/spawned, but I never return to the main thread to continue. This is not desired. This first thread down just does a sleep() and then increments a counter and prints it out. It will do this forever (until ^C).
I did find some issues with the pthreads implementation, it was throwing me some errors on some calls that I don't get on 3 other platforms (they are PPC based, same vintage Linux Kernel) and they all work just fine.
We've removed the customer driver's we had to build so as to rule out any interference from them. I get the same results.
For some reason, when running the "real" application, the thread is spawned but does not want to return to the main thread. The Code used is identical to what is in my test code that works.
Today, we rebuilt the .so libraries as .a's and created a static application, since the test code is just built as a stand-alone application, only links to -lrt, -lpthread. In this case, we get the same results, the thread is spawned, but never returns to the main thread.
This is very frustrating and is also critical: if a solution cannot be found, then the project is dead. The use of threading and thread priorities is mandatory for our application.
Has anyone experienced something similar with pthreads on ARM???
Any pointers would be greatly appreciated
TIA
Steve
Uhm only some pointer: first, not all operating systems are preemptible, so in very rare cases thread switching happens only because of I/O blocking calls (a thread waits for I/O, so other threads can continue). You can try with the pthread sched_yield that "causes the calling thread to relinquish the CPU".
Other thing, the "sleep" system call causes the whole process, not just a thread, to sleep. So, remember this before using it. Use "alarms" as a possible replacement for sleep in thread.
What is the scheduling algorithm and what is the scheduling priority for the spawned threads? If you are using Priority based scheduling and priority of the spawned threads is higher than the main, then you may be able to see such kind of behavior...
The question is which pthread implementation you use. The question is especially important in embedded environment, where you can have quite non-standard things. There are some that implementations that do not use system scheduling at all - they do it internally on system calls and pthread_yield(). Try to force the running thread to schedule and see what happens.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.