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 3855654
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:48:33+00:00 2026-05-19T17:48:33+00:00

NOTE: To understand my question, you might need to know about my project and

  • 0

NOTE: To understand my question, you might need to know about my project and the problem. If not, skip right to the “QUESTION” section at the bottom.


PROJECT

I’m working on a writing a C++ class that enables its parent to act like synchronous/blocking threads by having Pause() and Resume().

Here’s an example of how it would work.

class BlockingThread
   : public BlockingThreadBase // all the Asm magic happens in BlockingThreadBase
{
  void StartStopHere(void) // called upon the first Resume() call (pure virtual in base)
  {
    printf("1"); Pause();
    printf("3"); Pause();
    printf("5"); Pause();
  }
};

int main(void)
{
  BlockingThread obj;

  obj.Resume(); printf("2");
  obj.Resume(); printf("4");
  obj.Resume(); printf("6");

  return 0;
}

// OUTPUT: 123456

I’ve tried true threading and several novel ideas but they ended up too slow to transfer between code locations 21 million times per second.

My latest idea is use chunks of the stack (stack buffers) to create the illusion of multiple stacks. When obj1.Resume() is called, it would return to location of its personal stack, New #1 Stack, execute until Pause() and then return to the previous stack location it was at.


ILLUSTRATIONS

How the stack would look without anyBlockingThread objects in main().

 _________________
| Normal | Stack  |
| Stack  | Buffer |
|________|________|

How aBlockingThread object in main() would look like on the stack.

 ___________________________________
| Normal | Stack  | New #1 | Stack  |
| Stack  | Buffer | Stack  | Buffer |
|________|________|________|________|

How twoBlockingThread objects in main() would look like on the stack.

 _____________________________________________________
| Normal | Stack  | New #1 | Stack  | New #2 | Stack  |
| Stack  | Buffer | Stack  | Buffer | Stack  | Buffer |
|________|________|________|________|________|________|

PROBLEM

When moving to a “new” stack, and then calling obj.Resume() (from main) which in turn call StartStopHere() causes a segfault at the point of calling StartStopHere(). GDB says can't find linker symbol for virtual table for 'BlockingThreadBase' value when I try to get the value of a member variable from BlockingThreadBase. This is why I suspect it has the same problem when trying to find the location of StartStopHere() when it’s called.


QUESTION

(ignore the italics words if you didn’t read the other sections)

How can I find [and move or copy] the vtable (or its location if that’s what’s stored) of the class in the [normal] stack [to a new stack]?

  • 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-19T17:48:34+00:00Added an answer on May 19, 2026 at 5:48 pm

    I think what you’re looking for is cooperative threading. For a fast and simple implementation of it, check out libco. http://byuu.org/files/libco_v16.tar.bz2. The coswitching is implemented in raw assembly and works for x86, x86_64, PPC32 and PPC64. It also has implementation (ab)using setjmp/longjmp and posix ucontext (very slow).
    The overhead with this kind of stack swizzling is about 5x. 20 million swaps / sec should work fine. There are some test programs included to test speed.

    Example:

    #include "libco.h"
    #include <stdio.h>
    
    static cothread_t t1;
    static cothread_t t2;
    
    static void foo(void)
    {
       for (int i = 1; i < 10; i+=2)
       {
          printf("%d\n", i);
          co_switch(t1); // Swap back to main cothread
       }
    }
    
    int main(void)
    {
       // Get a handle to the current coinstance.
       t1 = co_active();
    
       t2 = co_create(10000, foo); // New cothread with stacksize 10000.
    
       for (int i = 0; i < 10; i+=2)
       {
          printf("%d\n", i);
          co_switch(t2); // Swap to cothread t2.
       }
    
       co_delete(t2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: This question changed a little as I learned more about the problem, so
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note The question below was asked in 2008 about some code from 2003. As
Please note this is a question with regard to Backbone.js. This is not a
Note: This similar SO question talks about how to build the same class, but
My question is about a field called contract_nm varchar2(14). I need to get 3
Technically this might not be classed as a programming question, since I have already
Note: This is a sequel to my previous question about powersets. I have got
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
Note: See the bottom of this post for an explanation for why this wasn't

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.