detached thread is causing program crash


 
Thread Tools Search this Thread
Top Forums Programming detached thread is causing program crash
# 1  
Old 03-30-2009
detached thread is causing program crash

Hi All,
I have scenario where my callback function data_update() can be called anytime. I have written the function data_update() such that it will create detached thread for processing the data sent to this function.
Code:
 
data_update()
{
   pthread_attr_t attr_thread;

   pthread_attr_init(&attr_thread);

   if ( pthread_attr_setdetachstate(&attr_thread, PTHREAD_CREATE_DETACHED) != 0 )
   {
      perror("pthread_attr_setdetachstate: ");
      return;
   }
   thrdArgObj = (threadArg *)malloc(sizeof(thrdArg));
   /* create argument for thread */
   threadArgObj->ClientLst = clntlst;
   if ( pthread_create(&threadId, &attr_thread, (void *)handleAsynchData, (void *)thrdArgObj) != 0 )
   {
      perror("pthread_create: ");
      return;
   }
   (void) pthread_attr_destroy(&attr_thread);
}

void *
handleAsynchData(void *ptr)
{
 thrdArgObj *thrdArg = (thrdArgObj *)ptr;
 (void)process_data(thrdArg->ClientLst);
 pthread_exit(NULL);
}

In the function handleAsynchData() I am calling another function process_data() to which the member of the structure threadArgObj is passed. Based on the client list, the function process_data() spends time in execution. It can be very short time for some list and a long time for some list. This function in turn, process the data and returns back. Here, since the function the function data_update() is a call back function it can be called at any time. This is the reason I have created detached thread. Also, I am making use og mutec for synchronization in the function process_data().

But, when I run my program. It runs fine for some time and then the program crashes. This I see consistently. Am I doing something wrong in the way I am creating detached thread or free attributes.
Please provide inputs

Last edited by Neo; 03-30-2009 at 12:38 PM.. Reason: added code tags
# 2  
Old 03-30-2009
Code tags for code please, they make code readable, which this is not. [ code ] stuff [ /code ] without the extra spaces in the tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to create core through program at the time of crash by handling signals?

I am in process of writing a library which can make any application of my product capable of creating core in the application's log folder with a product friendly core file name programatically. In my library I am registering for certain signals e.g. SIGILL, SIGFPE, SIGBUS, SIGSEGV, SIGSYS, SIGABRT... (5 Replies)
Discussion started by: rajeev_ks
5 Replies

2. AIX

How to create core through program at the time of crash by handling signals?

I am in process of writing a library which can make any application of my product capable of creating core in the application's log folder with a product friendly core file name programatically. In my library I am registering for certain signals e.g. SIGILL, SIGFPE, SIGBUS, SIGSEGV, SIGSYS, SIGABRT... (1 Reply)
Discussion started by: rajeev_ks
1 Replies

3. Solaris

Boot Solaris 10 from detached root mirrors

I recently ran some patching on a Solaris 10 server and as per normal procedure I detached the LVM root disk mirrors first to preserve the pre-patching copy of the OS. During the patching, I ran into some issues which I managed to resolve and completed the patching. However, I was looking around... (5 Replies)
Discussion started by: Grippo
5 Replies

4. UNIX for Dummies Questions & Answers

Run a detached process

Hey guys, Just wondering is there anyway that I would be able to run a detached process that would continue to run regardless of me being logged into the linux host? (4 Replies)
Discussion started by: killaram
4 Replies

5. Programming

when can we destory thread attributes using pthread_attr_destroy() for detached thrd

Hi All, I am creating detached threads using pthread_create(). As we know, we need to pass the thread attribute structure as an argument to the pthread_Create() API. I want to know what is the good time to destroy this thread attributes using pthread_attr_destroy() call. Also, I want to know... (2 Replies)
Discussion started by: wonderman
2 Replies

6. Filesystems, Disks and Memory

/dev/core "link to program crash data"

Hi there, I found a link to a file /dev/core of 17 GB Is it ok??? I couldn't find many information about it. Any suggestion would be appreciated!!! Thanks in advance, Giordano Bruno PS: I'm working with FEDORA 6 (2 Replies)
Discussion started by: Giordano Bruno
2 Replies

7. HP-UX

How do i cleanup the removed/detached devices ???

Hi, Am new to HPUX . I need your assistance.. I had attached a Clariion(storage) LUN into HPUX machine, devices with 2GB(c8t0d0) and 1GB(c8t0d1) space. Later some point of time, detached these devices from HPUX machine and executed 'insf' command to build the new devices directory special... (4 Replies)
Discussion started by: raghu265
4 Replies

8. Programming

POSIX - Hot to check if detached thread is still active

Hello, I have created program that run threads one by one, maximum 100. Each thread will process one block of data, and once it`s finished, new thread is created with new block of data....etc I have array of values to control status of each thread, like this: array_thread_status=1... (11 Replies)
Discussion started by: orangem
11 Replies

9. Programming

Can SIGTERM to main process kill the detached threads?

Hi, I am stuck up with a strange problem. I am writing an application - a kinda tracker that reads data from memcache and invokes theads to process each record of the memcache. I dont want to join all my threads because my tracker should poll the cache in regular intervals say sum 300... (2 Replies)
Discussion started by: deepti_v25
2 Replies

10. Solaris

Solaris DiskSuite, boot from detached disk

Hi, I am running Solaris 8 on Sun server with 2 hard drives. I have configured mirroring on the system using DiskSuite tool in order to have the same data on both disks. Now I want to perform some software upgrade and I would like to use the second disk as a backup disk. This means taking this... (3 Replies)
Discussion started by: carlossg
3 Replies
Login or Register to Ask a Question