Re: sharing objects

Hello Tedy,
You should be able to pass parameters to the function the new created
thtread  will execute. In c, we call the windows createThread
function, which takes some parameters, one of them being a function
address, which will contain the thread's code, and another being a
pointer which windows will pass to this function as its parameter.
Something like this: (pseldo but just like it is)
void* functionOfTheThread(void* param)
printf("I am a new thread!");

and we call:
createThread(threadOfTheFunction, someThingAsParam, bla bla);

You can notice that the createThread receives the address of the
function which countains the thread code, and also the params, which
will be available to the function of the thread as parameter.
Now, we could create something like this:

typedef struct{
obj1* Obj1;
obj2 *Obj2;
} threadParams, *lpThreadParams;

You can see that this structure holds two pointers, one to obj1 and
other to obj2.
Now, it is only necessary to alocate a instanse of obj1 and obj2 in
memory, copy its pointers to the struct, and pass the struct's address
to the thread function as the parameter.
This way you can use objects created outside of the thread inside of
it, but this is dangerous and can create pretty great troubles for you
if you don't know what you are trying to do.
Sorry for typing this way, but if you still having questions please ask again.

2008/2/22, Sina Bahram <sbahram@xxxxxxxxx>:
> Yes, this is definitely possible.
> Take care,
> Sina
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Octavian Rasnita
> Sent: Friday, February 22, 2008 12:53 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: sharing objects
> Hi,
> Does anyone know if in a C# program that uses more threads, the objects
> created in a thread can be used in other threads?
> For example an object that holds a database handle, or an object from the
> WinForms GUI.
> Same question for Java.
> Thank you.
> Octavian
> __________
> View the list's information and change your settings at
> __________
> View the list's information and change your settings at

When you say "I wrote a program that crashed Windows," people just
stare at you blankly and say "Hey, I got those with the system, for
Linus Torvalds
View the list's information and change your settings at

Other related posts: