?
Solved

multithreading

Posted on 1999-01-05
7
Medium Priority
?
265 Views
Last Modified: 2013-11-20
Two threads, thread A and B are created by an application. I need to call a method called M() in thread A from thread B. Does thread A execute the method in its own time slice or is the method executed in B's time slice? I have a choice as to where to put the method M. It can be in the application's main thread, or in A or in B. The method will always be called by B. Which thread should M belong to in order to achieve the best performance? Does this still apply if the method M is static?

0
Comment
Question by:maries032698
7 Comments
 

Expert Comment

by:koskia
ID: 1327263
tell us something about the environment
are you using MFC, or just win32 API's, OWL ???
in MFC every thread besides the main thread can be represented by a class, describe a little more.
0
 
LVL 1

Expert Comment

by:VAM345
ID: 1327264
Thread is not a program. Every thread that executed has own time slice. Thread is gust a function. When finish function, thread is finish. Every function why call inside thread is executed in that thread time slice.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1327265
>method called M() in thread A

Methods don't exist in threads, they exist in classes.  This means that wherever you call M() from, it will run in the context of the calling thread.

Therefore, the rest of your question doesn't really make sense as M() is just a callable object, and threads are threads which don't do anything but run.

The bottom line to your question is that M() is a function call, it doesn't matter where it is.  As long as thread B can reference the method M(), it can be called.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:maries032698
ID: 1327266
To jhance:

No need to be nasty. The question does make sense and I sill need an answer.
Lets clarify and say that the public method M() belongs to an object CMyObj that belongs
to a thread and which thread B has access to. The rest of my question remains the same.
If CMyObj belongs to thread A and B calls pThreadA->CMyObj::M() is the method M()
executed in thread A's time slice or B's?? The remainder of the original question is the same.


0
 
LVL 1

Accepted Solution

by:
VAM345 earned 100 total points
ID: 1327267
It is executed in time slice on thread B`s.
0
 
LVL 1

Expert Comment

by:pcj0961
ID: 1327268
I think your confused about what a thread is. If you have a object CMyObject and M() is
a member then it doesn't belong to any thread as one of the previous answers pointed out its a callable function. A thread can exists in the CMyObj object but the whole CMyObj
is not the thread.  M() can be called by the thread that is within the CMyObj object and
that call would execute on that threads time slice. If M() where called by a thread external to CMyObj then M() would execute on that threads time slice.
0
 

Author Comment

by:maries032698
ID: 1327269
Ok. I'm not confused about what a thread is. The thread contains the object CMyObj and M() belongs to CMyObj. A second thread has a pointer to the first one. The first one has the CMyObj. The second thread also has access to CMyObj through its pointer to the first thread. So the answer is your last sentence: M() is called by a thread that is external to CMyObj and M() is executed in the second thread's time slice.
thanks for the help.
I'd still like to know about static methods and data...

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question