Solved

multithreading

Posted on 1999-01-05
7
211 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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. …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

15 Experts available now in Live!

Get 1:1 Help Now