Search the web
Sign In
New User? Sign Up
cheapthreads · cheap_threads
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Cheap Threads and C++   Message List  
Reply | Forward Message #14 of 89 |
Re: [cheapthreads] Cheap Threads and C++

Oops. I forgot to include compilation guards in ct.h to ensure that
the Cheap Threads functions are declared as extern "C" when you
#include that header in a C++ file.

See the attachment for a slightly revised version of ct.h. Or you
can add the compilation guards yourself:

#ifdef __cplusplus
extern "C"
{
#endif

/* function prototypes here... */

#ifdef __cplusplus
}
#endif

With this change to the header, on my system I could compile cttimer
as a C++ program without alteration.

I will post this revision to the website this weekend.

Another possibility is to skip the compilation guards and compile all
the Cheap Threads modules as C++. I haven't tried it, and you might
need to tweak the code here and there if I left out a necessary
#include or something like that, but it ought to work.

I don't recommend that approach, though. For one thing, future
releases of Cheap Threads will include the compilation guards, so
if you upgrade to a new release you would have to remember to disable
them. Furthermore, compiling everything as C++ is likely to degrade
performance somewhat, at least if you compile with exceptions enabled.
The C++ compiler generates exception handling code that incurs
overhead even when no exceptions occur.

On the other hand you might want exceptions to propagate all the way
up through the scheduler into whatever calls ct_schedule(), so that
each thread doesn't have to include a lot of tedious code to keep
exceptions from escaping. If that's what you want, then you would
have to compile Cheap Threads as C++. Presumably you would be willing
to accept the extra overhead that would result.

Maybe I should make the compilation guards themselves subject to
conditional compilation. Then if you want to compile Cheap Threads
as C++, then you could compile it with CT_PLUSPLUS #defined, and the
compilition guards would be disabled, without your having to edit ct.h.

I'm reluctant to add yet another build option without feedback from
users. Does anybody have any preferences?

Thanks for writing. Please let us know how things turn out.

Scott McKellar mck9@...
http://home.swbell.net/mck9/ct/

Antz wrote:
>
> I've been playing around with the Cheap Threads download package on
> FreeBSD using the GNU C compiler (gcc) and so far it seems great.
> However I really need to use classes and some of the nice data structures
> in C++. Thus far trying to compile the cttimer test program using g++ has
> been utterly impossible.
> Is there any way that the cheap threads code can be used by a program
> written in C++? Or am I going to be forced to use POSIX threads and have
> to write completely different versions of this application for *NIX and
> Windows?
>
> Any help would be greatly appreciated.
> Thnx.
>
> -Antz

Fri Sep 5, 2003 4:34 am

jm407a
Offline Offline
Send Email Send Email

Attachment
ct.h
Type:
application/x-unknown-content-type-H_auto_file
Forward
Message #14 of 89 |
Expand Messages Author Sort by Date

I've been playing around with the Cheap Threads download package on FreeBSD using the GNU C compiler (gcc) and so far it seems great. However I really need to...
Antz
antz_ii
Offline Send Email
Sep 4, 2003
12:58 pm

Oops. I forgot to include compilation guards in ct.h to ensure that the Cheap Threads functions are declared as extern "C" when you #include that header in a...
Scott McKellar
jm407a
Offline Send Email
Sep 5, 2003
4:34 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help