Unable to put a Boost Thread asleep -


os: win7
ide: visual studio 2010
boost version: 1.47

i'm new boost , i'm trying simple. i've created single thread in header file , tried putting sleep. can't working. here code , compilation errors

main.h -

#pragma once    #include <conio.h>    #include <boost\thread.hpp>     boost::posix_time::seconds worktime ( 120 );   boost::this_thread::sleep ( worktime );   

main.cpp

#include "main.h"    void main ( void ) {     _getch(); }; 

output -

error c4430: missing type specifier - int assumed. note: c++ not support default-int error c2365: 'boost::this_thread::sleep' : redefinition; previous definition 'function' error c2491: 'boost::this_thread::sleep' : definition of dllimport data not allowed error c2482: 'boost::this_thread::sleep' : dynamic initialization of 'thread' data not allowed 

using following code now, in main.cpp:

#include <boost\thread.hpp> #include <conio.h>   void thread_func() {     boost::posix_time::seconds worktime ( 120 );     boost::this_thread::sleep ( worktime ); }  int main(int argc, char* argv[]) {     boost::thread t(thread_func);     _getch(); } 

receiving following errors:

1>libcmtd.lib(dbgheap.obj) : error lnk2005: __heap_alloc defined in libcmt.lib(malloc.obj)
1>libcmtd.lib(dbgheap.obj) : error lnk2005: __recalloc defined in libcmt.lib(recalloc.obj)
1>libcmtd.lib(dbgheap.obj) : error lnk2005: __msize defined in libcmt.lib(msize.obj)
1>libcmtd.lib(dbghook.obj) : error lnk2005: __crt_debugger_hook defined in libcmt.lib(dbghook.obj)
1>libcmtd.lib(isctype.obj) : error lnk2005: __isctype_l defined in libcmt.lib(isctype.obj)
1>libcmtd.lib(isctype.obj) : error lnk2005: __isctype defined in libcmt.lib(isctype.obj)
1>link : warning lnk4098: defaultlib 'libcmtd' conflicts use of other libs; use /nodefaultlib:library
1>fatal error lnk1169: 1 or more multiply defined symbols found

you calling boost::this_thread::sleep ( worktime ) outside of control flow. should like:

void thread_func() {     boost::posix_time::seconds worktime ( 120 );     boost::this_thread::sleep ( worktime ); }  int main(int argc, char* argv[]) {     boost::thread t(thread_func);     _getch(); } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -