Thread: Boost thread

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    69

    Boost thread

    Hello I have a problem. I wrote some code which I include in my application, it was wroking in CodeBlocks, but I changed enviroment to VS2010, now I have errors.

    This is ClientHandler.h :
    Code:
    #ifndef CLIENT_HANDLER_H
    #define CLIENT_HANDLER_H
    #include <windows.h>
    #include <boost/thread/thread.hpp>
    
    class ClientHandler
    {
          private:
    
          public:
             ClientHandler();
             ~ClientHandler(){}
             int StartListen();
             DWORD WINAPI ServeClient(int ID);
             DWORD WINAPI WaitClients(int ok);
    };
    
    extern ClientHandler CHandler;
    
    #endif
    This is ClientHandler.cpp:
    Code:
    #include "stdafx.h"
    #include "ClientHandler.h"
    #include <utility>
    
    ...
    
    int ClientHandler::StartListen()
    {
        if (StartedListen)
        {
            printf("ClientHandler::Initialize::Already Initialized!\n");
            return 0;
        }
    
        printf("ClientHandler::Initialize\n");
        if (NHandler.ListenSocket != INVALID_SOCKET)
        {
    	boost::thread thread(&ClientHandler::WaitClients, CHandler, 0); ///<------ not working
            listenthread = std::move(thread);
            StartedListen = 1;
        } else printf("ClientHandler::Listener::Startup failed\n");
    	return 0;
    }
    
    
    DWORD ClientHandler::WaitClients(int ok)
    {
    
    ...
    
    }
    What is get is :

    Code:
    1>  ClientHandler.cpp
    1>  Including from ClientHandler.cpp: Including NetworkHandler.h...
    1>  Included from ClientHandler.cpp: Included NetworkHandler.h...
    1>  Including from ClientHandler.cpp: Including thread.h...
    1>  Included from ClientHandler.cpp: Included thread.h...
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(318): warning C4180: qualifier applied to function type has no meaning; ignored
    1>          h:\boost_vs\boost_1_46_1\boost\bind\bind.hpp(313) : see reference to class template instantiation 'boost::_mfi::dm<R,T>' being compiled
    1>          with
    1>          [
    1>              R=DWORD (int),
    1>              T=ClientHandler
    1>          ]
    1>          h:\boost_vs\boost_1_46_1\boost\bind\bind_template.hpp(20) : see reference to function template instantiation 'void boost::_bi::list2<A1,A2>::operator ()<F,boost::_bi::list0>(boost::_bi::type<T>,F &,A &,int)' being compiled
    1>          with
    1>          [
    1>              A1=boost::_bi::value<ClientHandler>,
    1>              A2=boost::_bi::value<int>,
    1>              F=DWORD (__stdcall ClientHandler::* )(int),
    1>              T=void,
    1>              A=boost::_bi::list0
    1>          ]
    1>          h:\boost_vs\boost_1_46_1\boost\bind\bind_template.hpp(18) : while compiling class template member function 'void boost::_bi::bind_t<R,F,L>::operator ()(void)'
    1>          with
    1>          [
    1>              R=void,
    1>              F=unsigned long (__stdcall ClientHandler::* )(int),
    1>              L=boost::_bi::list2<boost::_bi::value<ClientHandler>,boost::_bi::value<int>>
    1>          ]
    1>          h:\boost_vs\boost_1_46_1\boost\thread\detail\thread.hpp(256) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled
    1>          with
    1>          [
    1>              R=void,
    1>              F=unsigned long (__stdcall ClientHandler::* )(int),
    1>              L=boost::_bi::list2<boost::_bi::value<ClientHandler>,boost::_bi::value<int>>
    1>          ]
    1>          b:\server\units\clienthandler.cpp(41) : see reference to function template instantiation 'boost::thread::thread<DWORD(__stdcall ClientHandler::* )(int),ClientHandler,int>(F,A1,A2)' being compiled
    1>          with
    1>          [
    1>              F=DWORD (__stdcall ClientHandler::* )(int),
    1>              A1=ClientHandler,
    1>              A2=int
    1>          ]
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(326): warning C4180: qualifier applied to function type has no meaning; ignored
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(331): warning C4180: qualifier applied to function type has no meaning; ignored
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(345): warning C4180: qualifier applied to function type has no meaning; ignored
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(350): warning C4180: qualifier applied to function type has no meaning; ignored
    1>h:\boost_vs\boost_1_46_1\boost\bind\mem_fn.hpp(362): warning C4180: qualifier applied to function type has no meaning; ignored
    1>h:\boost_vs\boost_1_46_1\boost\bind\bind.hpp(313): error C2064: term does not evaluate to a function taking 2 arguments
    1>          class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments
    1>  Generating Code...
    1>  Compiling...
    1>  NetworkHandler.cpp
    1>  Generating Code...
    1>
    1>Build FAILED.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    WINAPI maps to __stdcall.
    C++ member functions use __thiscall.

    MSVC seems to be confusing itself. Removing "WINAPI" fixed the errors in my testing.

    Also, CHandler is being copied by value. If you don't want this, then use:
    Code:
    boost::thread thread(&ClientHandler::WaitClients, boost::ref(CHandler), 0);
    Anything you don't want copies of can inherit from boost::noncopyable as well.

    gg

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    Quote Originally Posted by Codeplug View Post
    WINAPI maps to __stdcall.
    C++ member functions use __thiscall.

    MSVC seems to be confusing itself. Removing "WINAPI" fixed the errors in my testing.

    Also, CHandler is being copied by value. If you don't want this, then use:
    Code:
    boost::thread thread(&ClientHandler::WaitClients, boost::ref(CHandler), 0);
    Anything you don't want copies of can inherit from boost::noncopyable as well.

    gg
    Lol i forgot to change it in ClientHandler.h Thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Listening socket and thread problem
    By esaptonor in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2010, 03:04 AM
  2. Replies: 11
    Last Post: 06-09-2010, 07:31 PM
  3. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  4. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  5. pointer to main thread from worker thread?
    By draegon in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 06:35 AM