[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Trying to use cthread_fork() in the right way
From: |
Jose Luis Alarcon Sanchez |
Subject: |
Trying to use cthread_fork() in the right way |
Date: |
Thu, 24 Mar 2005 00:52:34 +0000 |
Hi guys.
In a "Hello style" simple ipc program for learn the mach_msg() call, i
have two functions, void send_integer() and receive_integer().
Obviously, the data first sent and after received is an integer.
In the main() function i have something like
int s, r;
mach_port_t destination;
..........
send_integer (destination, s);
receive_integer (destination, &r);
printf ("The received integer is : %d\n", r);
..........
In this way, the code works fantasticly, doing what is expected.
The problem begin when after see another example that use the cthreads
library
for produce threads into a task, i said to myself "ok, now i want that one
thread
execute the send function and another thread execute the reception function".
The form i see to use cthread_fork() is this
cthread_detach (cthread_fork (function_name, (void *) port_name));
but with this structure, is clear that there gonna be problems for tell that
the
sent integer is s and the received is r. I was wasting time trying some bad
ideas,
but the code don't do what i want.
First of all, it is possible do what i thinking about?. Maybe is simply silly
try
that every function was executed by a diferent thread. Maybe the the port
destination
can't be used by the two threads, for a rights problem, i don't know, i'm
trying to learn.
If yes, if is possible to get that one thread do the sending of the integer
and another
thread take this integer from the destination port.... how is the form (in
generic) to
use cthread_fork() for adapt it to this case?.
Maybe the previous structure of the program, with two separate functions for
send and
receive and two diferents variables (s for "what" is sent and r for "what" is
received)
do more dificult the adaptation to a threads case.
I hope "listen your voices" about this.
Thanks, very much.
Regards.
Jose.
- Trying to use cthread_fork() in the right way,
Jose Luis Alarcon Sanchez <=