Solved

multithreading

Posted on 1999-01-05
7
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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