This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Two threads -two messages - one mbox
- From: Matthias Gorjup <gorjup at norik dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: Sun, 20 Jun 2004 18:44:40 +0200
- Subject: [ECOS] Two threads -two messages - one mbox
Hello,
I am having problems with sending more than on mbox-meassage in one
loop-iteration from one thread to another. Below is the code we are using:
cyg_handle_t mbox_handle;
void *sock_msb;
#define THREAD1_NAME "Thread1"
#define THREAD2_NAME "Thread2"
unsigned char THREAD1_STACK[0x2000];
unsigned char THREAD2_STACK[0x2000];
static cyg_handle_t THREAD1_Handle;
static cyg_handle_t THREAD2_Handle;
static cyg_thread THREAD1_Thread;
static cyg_thread THREAD2_Thread;
int message1;
int message2;
void main()
{
cyg_thread_create(20,
Thread1,
(cyg_addrword_t)0,
RPC_THREAD1_NAME,
(void *)THREAD1_STACK,
0x2000,
&THREAD1_Handle,
&THREAD1_Thread);
cyg_thread_resume(THREAD1_Handle); // start thread 1
cyg_thread_create(22,
Thread2, // CBFTask
(cyg_addrword_t)0,
RPC_THREAD2_NAME,
(void *)RPC_THREAD2_STACK,
0x2000,
&THREAD2_Handle,
&THREAD2_Thread);
cyg_thread_resume(RPC_CB_TASK_Handle); // start thread 2
cyg_mbox_create(&mbox_handle,sock_msb);
}
void Thread1(void)
{
while (1)
{
cyg_thread_delay(1000);
cyg_mbox_put(mbox_handle, message1);
cyg_mbox_put(mbox_handle, message2);
}
}
void Thread2(void)
{
void *msg;
while(1)
{
cyg_mbox_get(mbox_handle, );
cyg_mbox_get(mbox_handle, );
}
}
If I only send one message and read one mesage, the code works fine. But if I
send two messages in one iteration, the system reboots after the first
iteration of the sending thread.
I must say that I need to send two integer values from one thread to another
during one iteration and the other thread needs to read both of them in one
iteration as well.
What could be wrong?
Should I use a global structure with two integer elements and then send only a
pointer to that structure (this would make it possible to send only one
message in one iteration)?
Should I use mutex-es or some other synchronizaiton mechanism?
Thank you all for your time
Matthias Gorjup
--
Matthias Gorjup
Norik Systems
www.norik.com
Tel: + 386 41 540 545
Tel: + 386 3 759 3077
Fax: + 386 3 759 3078
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss