Fundamental Threading? 
Author Message
 Fundamental Threading?

I have some fundamental questions.

I created an ATL simple object that is free-threaded. It has one function
called PlaceTrade that enter a symbol and a number of shares into a database
table along with a time stamp. I wanted to break it by making the symbol and
number of shares private members of the ATL class that implement this simple
interface. At the beginning of PlaceTrade I assign to these member the
parameters and then I use those private members in the database code. I
figured that between that initial assignment and the actual use there is
going to be a thread-switch and things will get messed up. Unfortunately,
things didn't get messed up.

The client is utilizing the CThreadPool class that comes with ATL server. I
have two kinds of queued request. One {NVDA, 4} and one {MSFT, 6}. I should
get things like {NVDA, 6} in the database to see things mess up. However,
nothing did. It is important to not that in the init function of the worker
class that I implement is where I get the interface pointer so I'm
definitely not doing an addref and release on each request but only after a
series of request.

During this experiement fundamental questions occurred as well.

1) My class have many threads in a thread pool running and each worker
thread acquires an interface pointer through a call to create instance. Is
the process aware enough to only load one instance of my COM server into the
address space of the process? That is, will my calls to CoCreateInstance be
such that they get there own class factory and that there is no chance they
will interfere with each?

2) If yes to the last question then how in the world can you possibly mess
things up in the manner that I'm working in if every threads operations
don't interfere with the other.

3) Can you make an interface pointer available to all threads in a process
by simply making it global? The fact that the threadfunc takes a DWORD
member makes me wonder if that thread can access more of what the calling
thread has to pass to it than just the DWORD by accessing globals set by the
calling thread?

Sorry, much of this is confused. Any comment will be appreciated.



Thu, 28 Apr 2005 09:32:44 GMT  
 Fundamental Threading?

Quote:
> 1) My class have many threads in a thread pool running and each worker
> thread acquires an interface pointer through a call to create
instance. Is
> the process aware enough to only load one instance of my COM server
into the
> address space of the process? That is, will my calls to
CoCreateInstance be
> such that they get there own class factory and that there is no chance
they
> will interfere with each?

Only one instance of the server are loaded, only one class factory, but
multiple instances of your object are created. Each such instance has
its own copy of member variables. So it looks like each thread has its
own copy of the object and the object's methods are never called
concurrently. Now, if you store those parameters in global variables, so
that multiple instances keep them in the same place, you have a chance
to run into trouble.

Quote:
> 2) If yes to the last question then how in the world can you possibly
mess
> things up in the manner that I'm working in if every threads
operations
> don't interfere with the other.

By sharing the same instance between multiple threads, or by utilizing
global or static variables.

Quote:
> 3) Can you make an interface pointer available to all threads in a
process
> by simply making it global?

Yes you can

Quote:
> The fact that the threadfunc takes a DWORD
> member makes me wonder if that thread can access more of what the
calling
> thread has to pass to it than just the DWORD by accessing globals set
by the
> calling thread?

You can access globals, or you can pack a pointer to some data structure
into that DWORD. In fact, are you sure the thread proc accepts a DWORD?
In most frameworks, it is declared to accept a void*.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sat, 30 Apr 2005 07:27:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Fundamental .NET question

2. Fundamental .NET question

3. Fundamental String Question!

4. ListView Fundamentals :: C#

5. Fundamental pointer misunderstanding -- please help

6. *Fundamental* book of this newsgroup

7. fundamental lack of understanding

8. C fundamentals.

9. What you think R C language fundamentals

10. Need to clarify some fundamentals .....

11. ATL/COM Fundamental Question

 

 
Powered by phpBB® Forum Software