Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Threaded Program in C++

Status
Not open for further replies.

miannone

Programmer
May 28, 2003
3
CA
I am attempting to write a multi-threaded program in C++ which looks into an Oracle database in different schemas. It then looks at a few tables and does some calculations and eventually repeats this process. Done sequentially this takes too long, so I am going to use multi-threading. The catch is that this has to be able to work in both a Windows enviromnent and a UNIX environment. I am under the impression that to do multi-threading in C++ it is dependant on the OS, and therefore I may need two classes for the multi-threading part, one which compiles when in UNIX and the other for when compiling in Windows. Is this assumption correct? Also I know there are some C++ add ons that may make multi-threading simpler (Example: ABC++, CC++, Charm++, HPC++, POOMA...). Has anyone used any of these and can recommend which might work well in my situation?

Thanks.
 
Have you ever heard of Cygwin?

describes it as
Cygwin is a Linux-like environment for Windows. It consists of two parts:
A DLL (cygwin1.dll) which acts as a Linux emulation layer providing substantial Linux API functionality.
A collection of tools, which provide Linux look and feel.

This allows you to write POSIX-compliant code that will work on Windows in addition to almost any Unix distribution.

I REALLY hope that helps.
Will
 
Thanks, that looks like it might be useful and I'm looking into it. But if anyone knows of any other tools I'd still be interested for comparision.
 
> I am attempting to write a multi-threaded program in
> C++...
What kinda portability are you looking for? WIthin the Unix flavors itself, their is a big difference the way threads are implemented and the APIs exposed to the programmers. Mach, Solaris, SVR, Digital Unix etc all have different libraries for multi-threading.

Having said that, you would like to know a bit about these implementations.

In Unix, a thread could be one of these classes:
1. Kernel thread
2. LWP - Light Weight Process
3. User thread

Kernel thread is not available to the programmer ( only for the OS - as the name suggests ). The other two - LWP and user threads are available to programmers/users. In market u get many user-level libraries like pthread, C thread for various flavors of unix. The catch is most of the user-level libs are based on the top of LWP so u may have some problems esp with u wanna do some task in real-time. Given the fact that u r writing for a database engine, it makes sense to set some "soft deadlines" kind things for your tasks/threads. The underlying implementation of LWP may not be useful for u and u may want to read more on it before going for the decision.

> I am under the impression that to do multi-threading in
> C++ it is dependant on the OS,
Yes, you are right but thats true only for Kernel threads and LWPs...User threads can be made completely independent of the OS...well, thats what true for Unix flavors....

> therefore I may need two classes for the multi-threading > part, one which compiles when in UNIX and the other for
> when compiling in Windows. Is this assumption correct?

Makes sense....u could have one class ( .h file ) that sets the API and the implementation (.cpp) for these could vary based on the OS u wanna port. Almost all of the .cpp will be written making using of POSIX calls but you may have to tune the things a bit to make them more efficient on a given OS.


> Also I know there are some C++ add ons that may make
> multi-threading simpler
I am sorry......I dunno any.

Thanks.

Viren
 
Thanks, thats helpful. I think I need to look into the topic a little further before I make a decision.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top