This is the mail archive of the ecos-discuss@sources.redhat.com 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: Two threads -two messages - one mbox


>>>>> "Matthias" == Matthias Gorjup <gorjup@norik.com> writes:

    Matthias> Hello,
    Matthias> I am having problems with sending more than on
    Matthias> mbox-meassage in one loop-iteration from one thread to
    Matthias> another. Below is the code we are using:

    <snip>

    Matthias> If I only send one message and read one mesage, the code
    Matthias> works fine. But if I send two messages in one iteration,
    Matthias> the system reboots after the first iteration of the
    Matthias> sending thread.

    Matthias> I must say that I need to send two integer values from
    Matthias> one thread to another during one iteration and the other
    Matthias> thread needs to read both of them in one iteration as
    Matthias> well.

    Matthias> What could be wrong?
    Matthias> Should I use a global structure with two integer
    Matthias> elements and then send only a pointer to that structure
    Matthias> (this would make it possible to send only one message in
    Matthias> one iteration)? Should I use mutex-es or some other
    Matthias> synchronizaiton mechanism?

I can see two obvious problems with your code.

1) you are creating and starting the threads before the
   synchronization data structures. In particular mbox_handle could
   get used by thread1() or thread2() before main() has created it. In
   your simple example code main() is likely to run at a higher
   priority then the other threads so there is not actually a problem,
   but that is likely to change as the code gets more complicated. It
   is a good idea to initialize all synchronization data structures
   before starting any threads.

2) you are not allocating any space for the mbox itself. Your sock_msb
   argument to cyg_mbox_create() is an uninitialized pointer so it
   will have a value of 0. Hence you are placing the mbox at location
   0, where the interrupt vectors are likely to be depending on the
   architecture you are using.

   I suspect that when you do the second mbox send you are overwriting
   a critical interrupt vector, and the next time an interrupt
   triggers the system will crash and burn.

   Instead you need to allocate space for the mbox, something like:

     cyg_handle_t  mbox_handle;
     cyg_mbox	   mbox_data;

     ...

     int
     main(int argc, char** argv)
     {
         cyg_mbox_create(&mbox_handle, &mbox_data);

         /* now create and start the threads */
     }

Bart

-- 
Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


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