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

  • SEARCH
  • Home
  • 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 6117383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:18:52+00:00 2026-05-23T15:18:52+00:00

Edit: I need to refactor this question, it has too many extraneous components to

  • 0

Edit: I need to refactor this question, it has too many extraneous components to be clear what my question (which is about C++) is. But anyone who can understand what I am asking please do answer.

I have a class which represents a thread. The threading library I am using, TinyThread++, starts a thread by creating a thread object, however there is no copy constructor for it. Which makes sense.. What would be the meaning of copying a thread anyway?

Previously I had been initializing my thread object E_thread this way:

class E_thread {
    E_threadRoutine m_routine;
    E_thread *m_parent;
    thread m_thread;
public:
    E_thread(void *(void*),void*,E_thread*);
};
E_thread::E_thread(void *func(void*), void *arg, E_thread* parent): 
         m_parent(parent), m_routine(func,arg), 
         m_thread(thread_function_common, &m_routine) 
         {}

Initializing the thread ctor in this fashion works, I am sending the pointer of the E_thread‘s m_routine member to the thread as its argument. The purpose of m_routine is to keep track of thread specific functionality to pass to the thread itself.

However now I want to make a change where I want to allocate m_routine more carefully. Now m_routine is a pointer and I will need to set it with

m_routine = new E_threadRoutineTypeX(func,arg,etc);

in the E_thread ctor body. But this means I can no longer initialize thread the way I have been. I tried putting

m_thread = thread(thread_function_common,m_routine);

in the body but this copies the thread object which I don’t want to do. There’s gotta be some syntax for doing this….

  • 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-23T15:18:52+00:00Added an answer on May 23, 2026 at 3:18 pm

    You can do the following: initialize m_routine using a function, that will return a new E_threadRoutine like so –

    m_routine(createThreadRoutine(func, arg))
    

    and have createThreadRoutine return a new E_threadRoutine whichever way you want. Then, you can initialize m_thread with (thread_function_common, m_routine). The use of createThreadRoutine is not mandatory, but it will let you do more than just a new, if that’s needed.

    For this to work, m_routine must appear before m_thread in the class, otherwise m_thread will be initialize before m_routine is set. See Constructor initialization-list evaluation order.

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

Sidebar

Related Questions

No related questions found

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.