ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Because I have to run the FuncA for many times for different objects, I am thinking it's probably better to run multithread so that each thread contains each object. I have just read a small tutorial in http://www.yolinux.com/TUTORIALS/Lin...ixThreads.html
However, I am still not sure how to start a thread if the arguments of FuncA is multiple.
Also, the pthread_t looks quite out-of-date and it's in C although it works in C++.
Could anyone give me any idea how to do this please?
pthread stand for Posix Thread, it's an interface definition to interact with a POSIX compliant system.... So the implementation you're using can be outdated if you're running an old system, but the interface isn't, or if it's the case it means that POSIX itself is outdated, and as far as I know, it's not the case...
Quote:
it's in C although it works in C++.
pthread implementation is wrotten in C, as all system relative tasks: read, write, ioctl, socket... because C _IS_ the UNIX native language... If you want something that is more "C++" look_and-feel, you have to find a wrapper, but if you take a look inside the wrapper code, you'll see call to the same C functions. But it isn't a silly question, if you want to use a wrapper, choose a good library, many are portable, that means that you will be able to compile the same code under POSIX (all UNICES) and non-POSIX (windows and ???), because the library replace the pthread_XXX functions with the one for non-POSIX system.
I think c++ boost library has a threading class (that's probably a wrapper for pthread) http://www.boost.org and its available in most distributions directly just need to install it.
Define your objects to be the thread. Basically, you need to define your objects to be functor-objects; then you can use Boost or a variation of such (perhaps a creation of your own?).
Multithreading does not multiply the computer's time and capabilities, but rather, divides it.
My instincts tell me that, if your task is highly resource-intensive, it is very unlikely that multithreading will help matters. Finding a more-optimized algorithm is much more likely to bring success.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.