This is the mail archive of the ecos-devel@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: exception rises calling cyg_thread_delete()


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]