CreateThread

J

Jim Johnson

I have a graphics program that draws some animations. How can I add
another thread to do so other stuff like file processing -OR- internet
query?

I heard I should use the C function - CreateThread()

any tutorial on using Thread in C++?

following is my main program
=====================
#include "ofMain.h"
#include "testApp.h"

int main( ){

ofSetupOpenGL(1024,768, OF_WINDOW); //
<-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:

ofRunApp(new testApp());

}
 
I

Ian Collins

Jim said:
I have a graphics program that draws some animations. How can I add
another thread to do so other stuff like file processing -OR- internet
query?

I heard I should use the C function - CreateThread()
There isn't a standard C++ function CreateThread(), it might be part of
a platform specific API.
any tutorial on using Thread in C++?
Have a look at boost threads.
 
S

Sam

Jim said:
I have a graphics program that draws some animations. How can I add
another thread to do so other stuff like file processing -OR- internet
query?

I heard I should use the C function - CreateThread()

any tutorial on using Thread in C++?

There is no CreateThread() function in the C or the C++ programming
language. This function is specific to your operating system. Consult your
operating system's documentation for more information.

Generally, a C function can be invoked by C++ by declaring the function
using the “extern "C"†heyword, ex:

extern "C" int strcmp(const char *, const char *);




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBH2ejOx9p3GYHlUOIRApsiAJ9Y9/zyPQAEeEMhRFY58dfuZiZHogCeKUzt
V6XlUgOf4zFSMSPQUCqzuF8=
=5lRU
-----END PGP SIGNATURE-----
 
R

red floyd

Top posting redacted.
> I mean this function on win32, any tutorial / sample code on how to
> use thread on win32?
>
> HANDLE WINAPI CreateThread(
> __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
> __in SIZE_T dwStackSize,
> __in LPTHREAD_START_ROUTINE lpStartAddress,
> __in_opt LPVOID lpParameter,
> __in DWORD dwCreationFlags,
> __out_opt LPDWORD lpThreadId
> );

If it's a Win32 API, then it's OT here. Ask in a newsgroup with Windows
or Microsoft in its name.
Please see
[http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9]

While you're on whichever group you're looking at, ask why you should
use _beginthreadex instead of CreateThread.
 
C

Carmen Sei

I mean this function on win32, any tutorial / sample code on how to
use thread on win32?

HANDLE WINAPI CreateThread(
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in_opt LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out_opt LPDWORD lpThreadId
);
 
O

owebeeone

I mean this function on win32, any tutorial / sample code on how to
use thread on win32?

HANDLE WINAPI CreateThread(
  __in_opt   LPSECURITY_ATTRIBUTES lpThreadAttributes,
  __in       SIZE_T dwStackSize,
  __in       LPTHREAD_START_ROUTINE lpStartAddress,
  __in_opt   LPVOID lpParameter,
  __in       DWORD dwCreationFlags,
  __out_opt  LPDWORD lpThreadId
);

OT ... yadda

Use some libs that have already done the hard work.

boost, Austria C++, ACE, CommonC++ just to name a few.

Here is how Austria C++ does it:
http://austria.svn.sourceforge.net/...32/code/at_win32_thread.cpp?view=markup#l_661
 
J

James Kanze

There is no CreateThread() function in the C or the C++
programming language. This function is specific to your
operating system. Consult your operating system's
documentation for more information.
Generally, a C function can be invoked by C++ by declaring the
function using the `extern "C"' heyword, ex:
extern "C" int strcmp(const char *, const char *);

Be very careful about this, though, since the `extern "C"' is
part of the type. Typically, system API functions which create
threads are pure C, and take a pointer to a C function---when
using them in C++, this must be a free function declared `extern
"C"'.

When all is said and done, I can only concur with some of the
other posters, and say: use a third party library. (Despite
it's weaknesses, I'd go with Boost for this one.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top