public inbox for ecos-devel@sourceware.org
 help / color / mirror / Atom feed
* exception rises calling cyg_thread_delete()
@ 2007-06-21 14:32 Mik Prog
  2007-06-21 14:36 ` Gary Thomas
  0 siblings, 1 reply; 3+ messages in thread
From: Mik Prog @ 2007-06-21 14:32 UTC (permalink / raw)
  To: ecos-devel

Hello everyone,

apologies if the argument has been discussed already (could not find
anything about it!).
I'm new in eCos world and now I am facing an annoying problem: I get a
crash calling cyg_thread_delete().

The exception I get is on Cyg_Alarm::~Cyg_Alarm(), which is called by
cyg_thread_delete().

The most annoying thing is that this crash happens randomly: I have an
environment running 7 threads, out of which 6 should be deleted.
Deleting the first one is usually Ok and crash happens when deleting
2nd or 3rd or 4th and so on... randomly.

I first call the release function, just to unlock pending calls:

    cyg_thread_release( *(cyg_handle_t*)(pHandle) );

then the deletion one, which crashes:

    if ( ! cyg_thread_delete (*(cyg_handle_t*)(pHandle)) )
    {
        diag_printf("\nERROR: Thread deletion failed!\n");   // I
don't get this: an exception arise.
    }

I've tried to suspend the thread before delete it, but doesn't help.

Does anyone has any clue about what is going on?


Any help would be appreciated!
Thanks a lot!
 Mik

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: exception rises calling cyg_thread_delete()
  2007-06-21 14:32 exception rises calling cyg_thread_delete() Mik Prog
@ 2007-06-21 14:36 ` Gary Thomas
  2007-06-23 10:21   ` Mik Prog
  0 siblings, 1 reply; 3+ messages in thread
From: Gary Thomas @ 2007-06-21 14:36 UTC (permalink / raw)
  To: Mik Prog; +Cc: ecos-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mik Prog wrote:
> Hello everyone,
> 
> apologies if the argument has been discussed already (could not find
> anything about it!).
> I'm new in eCos world and now I am facing an annoying problem: I get a
> crash calling cyg_thread_delete().
> 
> The exception I get is on Cyg_Alarm::~Cyg_Alarm(), which is called by
> cyg_thread_delete().
> 
> The most annoying thing is that this crash happens randomly: I have an
> environment running 7 threads, out of which 6 should be deleted.
> Deleting the first one is usually Ok and crash happens when deleting
> 2nd or 3rd or 4th and so on... randomly.
> 
> I first call the release function, just to unlock pending calls:
> 
>    cyg_thread_release( *(cyg_handle_t*)(pHandle) );
> 
> then the deletion one, which crashes:
> 
>    if ( ! cyg_thread_delete (*(cyg_handle_t*)(pHandle)) )
>    {
>        diag_printf("\nERROR: Thread deletion failed!\n");   // I
> don't get this: an exception arise.
>    }
> 
> I've tried to suspend the thread before delete it, but doesn't help.
> 
> Does anyone has any clue about what is going on?

Are you sure your handle is correct?  I think you may be
dereferencing it improperly.

- --
- ------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
- ------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFGeo0AmaKbSsQGV8ARAu8vAJ9qlguU807KifucZRsGoR0YQaGhrwCeJBN9
2K+bzmqhyQaHZVzFtKoOU9I=
=nR79
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: exception rises calling cyg_thread_delete()
  2007-06-21 14:36 ` Gary Thomas
@ 2007-06-23 10:21   ` Mik Prog
  0 siblings, 0 replies; 3+ messages in thread
From: Mik Prog @ 2007-06-23 10:21 UTC (permalink / raw)
  To: ecos-devel

On 6/21/07, Gary Thomas <gary@mlbassoc.com> wrote:
[..]
> Are you sure your handle is correct?  I think you may be
> dereferencing it improperly.

Thank you Gary.
I've been through the pointers over and over again.
At the end I've decided to use a static array of cyg_handle_t for
thread creation/deletion... where my starting pointer points to (I
can't get rid of it).
So:

#define MAX_NUM_THREADS         10

static cyg_thread ThreadsHolder[MAX_NUM_THREADS];
static cyg_handle_t HandlesHolder[MAX_NUM_THREADS];

static I2 threadCounter = 0;            //number of allocated threads

// Threads creation
{
[..]
  HandlesHolder[threadCounter] = 0;

  cyg_thread_create ((cyg_addrword_t)prio,
                      (cyg_thread_entry_t*)pd,
                      (cyg_addrword_t)pData,
                      (char*)pName,
                      (void*)pbos,
                      (cyg_ucount32)stksize,
                      &HandlesHolder[threadCounter],
                      &ThreadsHolder[threadCounter]
                     );

  *pHandle = &(HandlesHolder[threadCounter]);
  threadCounter++;

  cyg_thread_resume ( HandlesHolder[threadCounter-1] );
[..]
}

//****************************************
// Threads deletion
int pTask_Delete (TaskHandle_t **pHandle)
{
       threadCounter--;

       // I search for the index of the handle of the thread to be deleted
       for ( i=0; i<MAX_NUM_THREADS; i++)
       {
               if ( **pHandle == &(HandlesHolder[i]) )
                       break;
       }

       while ( ! cyg_thread_delete ( HandlesHolder[i] ) )
       {
               diag_printf("\nERROR: Thread deletion failed! sleep... ");   //I
NEVER GET THIS
               cyg_thread_delay(1);
       }

       diag_printf("\n\n\n _OK_ ");   //NEVER GET THIS

       HandlesHolder[i] = 0;
      [..]
}


So what happens is that the cyg_thread_delete() call happens with the
proper handle (checked using debugger), but the call never returns!
The same happens with cyg_thread_kill.
Also, adding a cyg_thread_release() before the kill/delete call...
doesn' t help: but it does return.

To resume all threads go to deletion procedure, but none of the
returns... the process execution goes on and then when it tries to
allocate some memory in the thread heap crashes. And I start crying.

Any idea guys?
Thanks for your help!
Mik

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-23 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-21 14:32 exception rises calling cyg_thread_delete() Mik Prog
2007-06-21 14:36 ` Gary Thomas
2007-06-23 10:21   ` Mik Prog

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).