Solved

multithreading

Posted on 1999-01-05
7
238 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 180
maven archtype selection in eclipse 1 57
Is there a simple front-end menu system. 9 105
Problem to App source 6 75
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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