-
June 7th, 2014, 08:09 PM
#1
How to decide which type of thread to use?
There are gnu thread, c thread, posix thread and win32 thread
which all can be used on windows platform.
How, why and when do I need them?
Code:
#ifndef C_THREAD_H_
#define C_THREAD_H_
extern "C"
{
#include <cthread.h>
}
#ifndef BOOLEAN_H_
# include <Common/Boolean.h>
#endif
class Thread;
/*
* General notes: the C Threads library does not have any notion of priorities.
*/
/*
* This is a threads interface to the C threads library.
*/
class ThreadData
{
public:
ThreadData ();
~ThreadData ();
cthread_t cid;
mutex_t mx;
Boolean dead;
static void* Execute (void* p1);
static long base_key;
static Thread* mainThread;
static long mainThreadID;
};
class C_Mutex : public Mutex
{
public:
C_Mutex ();
~C_Mutex ();
Boolean lock ();
Boolean unlock ();
private:
mutex_t _theLock;
};
#endif
This simply won't compile with Visual C++ because there isn't any cthread.h header file there.
Thanks
Jack
Last edited by lucky6969b; June 7th, 2014 at 09:14 PM.
-
June 7th, 2014, 09:32 PM
#2
Re: How to decide which type of thread to use?
On Windows, I use:
_beginthreadex and QueueUserWorkItem.
-
June 7th, 2014, 10:19 PM
#3
Re: How to decide which type of thread to use?
Do I need to make up a variable in order to "hold" the thread?
I notice that _beginthreadex just returns a handle.
http://msdn.microsoft.com/en-us/library/kdzttdcb.aspx
Thanks
Jack
-
June 7th, 2014, 11:58 PM
#4
Re: How to decide which type of thread to use?
Originally Posted by lucky6969b
Yes, The link you posted contains an example of _beginthreadex. Also check out QueueUserWorkItem - it's a thread pool mechanism.
-
June 8th, 2014, 02:04 AM
#5
Re: How to decide which type of thread to use?
Originally Posted by lucky6969b
There are gnu thread, c thread, posix thread and win32 thread
which all can be used on windows platform.
How, why and when do I need them?
And then there are the C++ 11 threads. Concurrency is now part of standard C++,
http://www.amazon.com/gp/product/193...pf_rd_i=507846
-
June 8th, 2014, 01:13 PM
#6
Re: How to decide which type of thread to use?
Originally Posted by razzle
That would definitely be a better way to go if you are using C++ 11 or better.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|