Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:20:39+00:00 2026-05-30T23:20:39+00:00

If I do something like class myclass : public somelibrary::thread Are all methods called

  • 0

If I do something like class myclass : public somelibrary::thread

  1. Are all methods called on myclass executed in their own thread?
  2. Is only run() executed in its own thread?
  3. For every method to be executed in its own thread, do I have to create a new thread in each method?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:20:41+00:00Added an answer on May 30, 2026 at 11:20 pm

    If I do something like class myclass : public somelibrary::thread
    does this mean that all methods called on myclass will be called in
    their own thread?

    Not necessarily. It depends on the design of somelibrary::thread. In fact, Boost.Thread is not used this way (via inheritance). In that case, you simply create a new boost::thread object passing in a callable object (functors, function pointers, etc.) into its constructor.

    However, I haven’t seen any thread library where calling any method on a class derived from somelibrary::thread spawns a new thread. That is asking for data races, unless everything is somehow synchronized. But then your code would be wasting a lot of time waiting on synchronization primitives. Not to mention that threads are relatively expensive in terms of operating system resources. An application may have at most several threads running at any one time assuming it wasn’t designed by an idiot. Methods on the other hand may be called many, many times during the application running time.

    Is the only thing run in it’s own thread in the “run” method of such
    thread?

    Not all thread libraries call a run() method when running a new thread. For example in Boost.Thread, the entry point is operator()(). But yes, the entry point runs in its own thread, separate from the calling thread. All methods called by run(), directly or indirectly, runs in the newly-spawned thread.

    If only the run method is executed in it’s own thread, what if I want
    every method to be called in it’s own thread instead of just that one?

    This is almost certainly not what you actually want in C++, because of the fact that threads are very expensive in terms of operating system resources. You’ll be making your operating system waste time allocating and destroying threads all the time. Even in languages like Erlang, where threads are extremely cheap compared to OS threads, you don’t typically spawn a new thread for every single method. A program running many threads or constantly creating/destroying threads is a sign of a badly-designed program.

    Do I have to create a new thread in each method?

    Yes, if you want each method to run in its own thread, but again, you almost certainly don’t want this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class, something like the following; class MyClass { public: MyClass();
I want do something like that: public class MyClass { public String varA{ get;
Say i have something like: [DataContract(Namespace=http://bla.bla)] public class MyClass { [DataMember] public long ResponseCode
I have something like this: namespace MyNamespace { public partial class MyClass: UserControl {
I have a class which looks something like this: class MyClass { public: //
Say I've got something like that in a public header: class MyClass { public:
Okay, I have something like this in C++: class MyClass{ private: int someVariable; int
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
If I set a Friend-level scope on a setter, like this... Public Class MyClass
lets say I have a class like this: public class MyClass { private String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.