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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:13:54+00:00 2026-06-17T14:13:54+00:00

I am using VS2012 and I want to set thread priority from within a

  • 0

I am using VS2012 and I want to set thread priority from within a running thread. The goal is to initialize all threads with the highest priority state. To do this I want to get a HANDLE to the thread.

I am having some trouble accessing the pointer that corresponds to the thread object.

Is this possible?

From the calling main thread, the pointer is valid and from the C++11 thread it is set to CCCCCCCC. Predictably dereferencing some nonsense memory location causes a crash.

The code below is a simplified version showing the problem.

#include "stdafx.h"
#include <Windows.h>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>
#include <atomic>
using namespace std;
class threadContainer
    {
    thread* mT;
    condition_variable* con;
    void lockMe()
        {
        mutex m;
        unique_lock<std::mutex> lock(m);
        con->wait(lock);//waits for host thread
        cout << mT << endl;//CCCCCCCC
        auto h = mT->native_handle();//causes a crash
        con->wait(lock);//locks forever
        }
    public:
        void run()
            {
            con = new condition_variable();
            mT = new thread(&threadContainer::lockMe,*this);
            cout << mT << endl; //00326420
            con->notify_one();// Without this line everything locks as expected
            mT->join();
            }
    };
int _tmain(int argc, _TCHAR* argv[])
    {
    threadContainer mContainer;
    mContainer.run();
    return 0;
    }
  • 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-06-17T14:13:55+00:00Added an answer on June 17, 2026 at 2:13 pm
    #include <mutex>
    #include <condition_variable>
    #include <iostream>
    #include <atomic>
    #include <thread>
    
    class threadContainer {
       std::thread* mT;
      std::mutex m;
      void lockMe() {
        // wait for mT to be assigned:
        {
          std::unique_lock<std::mutex> lock(m);
        }
        std::cout << "lockMe():" << mT << "\n";
        auto h = mT->native_handle();//causes a crash
        std::cout << "Done lockMe!\n";
      }
      public:
        void run() {
          // release lock only after mT assigned:
          {
            std::unique_lock<std::mutex> lock(m);
            mT = new std::thread( [&](){ this->lockMe(); } );
          }
          std::cout << "run():" << mT << "\n"; //00326420
          mT->join();
        }
    };
    
    int main() {
      threadContainer mContainer;
      mContainer.run();
      return 0;
    }
    

    Try that.

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

Sidebar

Related Questions

I am using VS2010,C# to develop a Silverlight web based game. I want to
I am building a Windows forms application using VS2010. I want to read the
I want to run an .exe file in hidden mode using vc++ in VS2010.
I am using VS2012 and having some troubles publishing an mvc4 website. None of
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I want to output to my console a nicely formatted table with data from
I have recently had to move my project from using the CPython 2.6 interpreter
currently I am running my web service from following path http://localhost:16022/MachineService.asmx and usage of
I am new to workflow foundation and I am using workflow foundation 4.5 (VS2012

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.