Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

dchabaud

@dchabaud
About
Posts
4
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Call to std::thread::join() in the destructor of a global variable
    D dchabaud

    Yeh, it seems to be the same thing. I checked under Linux with GCC and it works. On my point of view, Visual C++ runtime after exiting the main() destroys all the threads then all the global variables, instead of the opposite.

    C / C++ / MFC question

  • Call to std::thread::join() in the destructor of a global variable
    D dchabaud

    Not exactly, the destructor of the global variable sets an atomic to tell the thread to exit.

    C / C++ / MFC question

  • Call to std::thread::join() in the destructor of a global variable
    D dchabaud

    I have the following code and when running it stays blocked on the join(). So, is it possible to call std::thread::join() in the destructor of a global variable?

    void MyTimerFunction();

    class MyGlobal
    {
    public:
    std::atomic<bool> m_Flag;
    std::thread m_GlobalThread;

    MyGlobal() {
        m\_Flag = true;
        m\_GlobalThread = std::thread(MyTimerFunction);
    }
    
    ~MyGlobal()
    {
        m\_Flag = false;
        if (m\_GlobalThread.joinable())
            m\_GlobalThread.join();
        std::cout << "MyGlobal destroyed" << std::endl;
    }
    

    };

    MyGlobal Test;

    void MyTimerFunction()
    {
    do
    {
    std::this_thread::sleep_for(std::chrono::seconds{10});
    if (!Test.m_Flag)
    break;

        std::cout << "New tick" << std::endl;
    } while (true);
    
    std::cout << "Exit MyTimerFunction" << std::endl;
    

    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    std::cout << "Main thread sleeping..." << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds{15});
    std::cout << "Main thread awaking..." << std::endl;

    std::cout << "Main thread returning..." << std::endl;
    return 0;
    

    }

    C / C++ / MFC question

  • CSocket::Connect returns WSAEISCONN
    D dchabaud

    I have a MFC serveur and a MFC client which work fine in most cases except 1 (the client and the serveur are in different Active Directory trees on the same network). On the client I use : m_pConnectionSocket = new CSocket(); if (m_pConnectionSocket && m_pConnectionSocket->Create()) { if (m_pConnectionSocket->Connect(m_strLicenseServerName, TCP_PORT_3)) { ... } } In the case it does not work Connect returns WSAEISCONN error which make no sense on my point of view. Any idea ?

    C / C++ / MFC c++ sysadmin windows-admin help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups