Solved

multithreading

Posted on 1999-01-05
7
223 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 165
string initialization in java 11 110
sum13 challenge 24 90
ShiftLeft challenge 21 78
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now