Sign in to follow this  
TheFlea

2 functions...

Recommended Posts

How can I make 2 functions both working in my programme... I read in Volume 2 by Bruce Eckel in chapter Concurency ...but i don't understand very well how I can make this programme work @Purice

Share this post


Link to post
Share on other sites
Without any more information, here's the best I can do:

#include <stdio>

void foo()//Defines the first function
{
std::cout<< "Function Foo";
}

void bar()//Defines the second function
{
std::cout << "Function Bar";
}

int main()
{
foo();//Runs the first function

bar();//runs the second function
}


But please tell us what language you're using, at the very least. I've just geussed that you're using C++, if I'm wrong, then my time has been totally wasted. So please save everyone the hassle and give all relevant information.

Share this post


Link to post
Share on other sites
He mentioned a book about concurency, so I presume what he wants is information regarding threads or something similar. Of course more information is needed...

Share this post


Link to post
Share on other sites
Yes, you definitely need to give a language. This would be easy in a language designed for this (like Erlang), but more difficult in a language like C or C++. Also, Bruce Eckel never made a book called "Volume 2" that I am aware of.

Share this post


Link to post
Share on other sites
check out openMP or google threading if your new to this. Just keep in mind that even if you use threads, on a single cpu machine, you'll only ever have one thread executing at once.

Cheers
Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi... The language is C/C++
I wrong when I say "Volume 2", I want to say "Thinking in C/C++" by bruce

the problem are threads I read in this book something like library "ZThread", but in don't how to using this library
I want to use 2 funtions in program at the same time.

@Purice



Share this post


Link to post
Share on other sites
Are you *sure* that you want to use threads? Is this really what you want? Chances are, you could do the same thing without using threads with much less of a hassle for you.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
Are you *sure* that you want to use threads? Is this really what you want? Chances are, you could do the same thing without using threads with much less of a hassle for you.


I'd be interested in knowing how?

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
Quote:
Original post by Ezbez
Are you *sure* that you want to use threads? Is this really what you want? Chances are, you could do the same thing without using threads with much less of a hassle for you.


I'd be interested in knowing how?

Cheers
Chris


Boost.Threads provides a library for portable C++ multithreading. The documentation also starts off with a pretty clear warning about exactly how difficult proper multithreading can be.

The ZThread library the OP mentioned is found on Sourceforge and provides doxygen created documentation.

Share this post


Link to post
Share on other sites
But those are still threads. The poster said you could run 2 funcitons simultaneously without threads:).

Cheers
Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Hi... The language is C/C++
I wrong when I say "Volume 2", I want to say "Thinking in C/C++" by bruce

the problem are threads I read in this book something like library "ZThread", but in don't how to using this library
I want to use 2 funtions in program at the same time.

@Purice




You have to be more specific in what you mean. What are you using this for and why do you need to run 2 functions 'at the same time'??

If you mean 2 long computational processes/executional sequences running simultaneously, then yes threads are the way to go (but fairly complicated especially if the two functions access the same data). If each step of the operation/function is of short duration, then you can do your own scheduling -- running them alternately in the same process (they thus cannot interrupt each other and is simpler).







Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
But those are still threads. The poster said you could run 2 funcitons simultaneously without threads:).

Cheers
Chris


He probably meant that he could probably do what he wanted without any sort of multitasking.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this