Re: creating thread in C++



mthread wrote:
On Dec 26 2007, 11:24 pm, Marcel Müller <news.5.ma...@xxxxxxxxxxxxxxx>
wrote:
...
myclass* m = new myclass();
_beginthread(&myclass::threadstub, NULL, 0, m);

This is defined behaviour as long as you always pass a non-NULL pointer
to myclass together with the function pointer &myclass::threadstub to
_beginthread.

Because there are some object lifetime issues and so on, there are
libraries like boost::thread that make your life easier. You should
think about using them.

Marcel


Hi thanx,
I am able to create thread now. I have used a static function. Can
u tell me how to use the free function
to create thread.

You shouldn't really do that, a static member function does not have
required extern "C" linkage.

One simple solution is the changer your static member to a friend
function and declare it (before the class definition) extern "C".

--
Ian Collins.
.



Relevant Pages

  • Re: why no copy constructor in java?
    ... Here only the pointer value is copied, both pointers will then point to ... MyClass Obj_1 = MyClass; ... default memberwise shallow copy then Obj_1 and Obj_2 will both have ... > behaviour(shallow copying) is usually un-acceptable. ...
    (comp.lang.java.programmer)
  • Re: TRICK: Unique IDing
    ... > pointer to the target instance or a pointer to a copy of the target ... When passing an instance of a class it can be done so the ... > class MyClass ... > you want ) and compare it against the suspect. ...
    (microsoft.public.dotnet.languages.vc)
  • TRICK: Unique IDing
    ... Sometimes it's hard to get straight when passing or storing or returning an ... pointer to a copy of the target instance. ... class MyClass ... ID) and compare it against the suspect. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Conversion from void* to a point of a class
    ... Well, that is true, dynamic_cast does not work for void-pointers - once you have converted your MyClass* pointer to a void* you have voluntarily given up all type information and there is no safe way back. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Using a macro, can I change what type an object is being cast to?
    ... > class has a static member function that acts a dummy callback (called by the ... > pointer to a subclass) and uses that to call non-static member functions. ... > function before the subclass object has been constructed fully thus calling ...
    (comp.lang.cpp)

Loading