pnaven03
Posts: 139
Joined: Thu Feb 16, 2017 5:21 pm

LonRun : thread hang and not responding in raspberry pi 3

Fri Apr 28, 2017 6:05 am

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

YCN-
Posts: 246
Joined: Fri Jun 10, 2016 3:18 pm

Re: LonRun : thread hang and not responding in raspberry pi

Fri Apr 28, 2017 7:29 am

Hi,

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");
}

pnaven03
Posts: 139
Joined: Thu Feb 16, 2017 5:21 pm

Re: LonRun : thread hang and not responding in raspberry pi

Fri Apr 28, 2017 9:02 am

Thanks for the reply,

Text file attached , please can you help me on this.

Regards,
Nv

pnaven03
Posts: 139
Joined: Thu Feb 16, 2017 5:21 pm

Re: LonRun : thread hang and not responding in raspberry pi

Fri Apr 28, 2017 11:11 am

Please any one response above issue.

StuartF
Posts: 30
Joined: Sun Feb 02, 2014 5:41 pm

Re: LonRun : thread hang and not responding in raspberry pi

Sat Apr 29, 2017 11:19 pm

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.

Code: Select all

if( fp == NULL ) 
{
<fail message>
}
else
{
<write to fp>
<close fp>
}
Another suggestion would be to have the thread function look like this to help see if the thread has exited.

Code: Select all

while(1)
{
<function>
}
fprintf( stdout, "this thread exit message" );

pnaven03
Posts: 139
Joined: Thu Feb 16, 2017 5:21 pm

Re: LonRun : thread hang and not responding in raspberry pi

Tue May 02, 2017 4:25 am

Thanks for the reply,

code changes are done as per your inputs,testing is going on.

Regards,
Nv

tommylee2k
Posts: 56
Joined: Mon May 08, 2017 6:23 am

Re: LonRun : thread hang and not responding in raspberry pi

Mon May 08, 2017 11:22 am

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.

Return to “C/C++”