Hi Team,
Am using raspberry pi 3 and kernel version Linux raspberrypi 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux, i written small application with 3 threads , one thread reading some battery status , second thread running adc values and on more threads reading gpio led's status etc, am running long run after one to two days second thread hang not running, how to debug this isuue , not even enter that thread. remain two threads running without any issues, please any one help why one thread is hang and how to debug this issue(c application).
code :
pthread_t thread, thread1, thread2;
pthread_create(&thread,NULL,&check_batterystatus, NULL);
pthread_create(&thread1,NULL,&adcdata_read, NULL);
pthread_create(&thread2,NULL,&check_ledstatus, NULL);
void * adcdata_read(void * arg)
{
while(1)
{
read adc data from dev system
}
}
void * check_ledstatus(void * arg)
{
while(1)
{
check the led and gpio status
}
}
void * check_batterystatus(void * arg)
{
while(1)
{
check the battery status
}
}
Regards,
Nv
Re: LonRun : thread hang and not responding in raspberry pi
Hi,
We need more info on your code to know what could possibly do the issue.
BTW can you post it under Code signs ?
We need more info on your code to know what could possibly do the issue.
BTW can you post it under Code signs ?
Code: Select all
int main (void){
printf("incredibly better isn't it ? \n");
}
Re: LonRun : thread hang and not responding in raspberry pi
Thanks for the reply,
Text file attached , please can you help me on this.
Regards,
Nv
Text file attached , please can you help me on this.
Regards,
Nv
Re: LonRun : thread hang and not responding in raspberry pi
Please any one response above issue.
Re: LonRun : thread hang and not responding in raspberry pi
There is a return NULL in the adc function that may be causing the problem.
Also, when you check for fp == NULL, it may be wise to use an else condition for the output.
e.g.
Another suggestion would be to have the thread function look like this to help see if the thread has exited.
Also, when you check for fp == NULL, it may be wise to use an else condition for the output.
e.g.
Code: Select all
if( fp == NULL )
{
<fail message>
}
else
{
<write to fp>
<close fp>
}
Code: Select all
while(1)
{
<function>
}
fprintf( stdout, "this thread exit message" );
Re: LonRun : thread hang and not responding in raspberry pi
Thanks for the reply,
code changes are done as per your inputs,testing is going on.
Regards,
Nv
code changes are done as per your inputs,testing is going on.
Regards,
Nv
-
- Posts: 56
- Joined: Mon May 08, 2017 6:23 am
Re: LonRun : thread hang and not responding in raspberry pi
if you have a multithreaded program, that (seems to) work for hours/days and then crashes, or hangs, that's often a problem with resources you use in several threads, and - eventually - access at the same time with 2 threads.
to make sure the resource is safe for beeing read (or write), you have to use a mutex;
You can think of a mutex as some kind of "flag" that can only be locked once. If some thread (t1) already has it locked, and another thread (t2) tries to lock it too, the 2nd lock will make the t2 sleep until t1 releases the lock.
This way, only one thread can access the resource at a time.
to make sure the resource is safe for beeing read (or write), you have to use a mutex;
You can think of a mutex as some kind of "flag" that can only be locked once. If some thread (t1) already has it locked, and another thread (t2) tries to lock it too, the 2nd lock will make the t2 sleep until t1 releases the lock.
This way, only one thread can access the resource at a time.