Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

multithreading in C++ using solaris

Posted on 2007-11-23
12
Medium Priority
?
628 Views
Last Modified: 2010-03-23
Hi,

I would like to generate a program which will be used by multiple clients at a time. For this, I would go for a multithreading program. Please explain me this with some simple examples.

Thanks,
shankarraj
0
Comment
Question by:shankarraj
  • 4
  • 2
  • 2
  • +3
12 Comments
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 20339641
I assume you know what multithreading means.....
Check out

www.sun.com/software/whitepapers/solaris9/multithread.pdf
developers.sun.com/solaris/library/topics/index.jsp

let me know if you need more help
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20339649
Multithreading is closely related to operating system. So, which one are you using?
0
 
LVL 86

Accepted Solution

by:
jkr earned 172 total points
ID: 20339706
Take a look at Pthreads, that library is the most commonly used multithreading environment on UN*X platforms: http://www.llnl.gov/computing/tutorials/pthreads/ ("POSIX Threads Programming")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20339711
oops, sorry, I didn't see the "using solaris" in the title.

@jkr,
 have you any comment about this question?
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22975992.html?cid=238
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 164 total points
ID: 20339787
>> Please explain me this with some simple examples
Hmmm... multi-threaded programming is NOT something that can be demonstrated with a couple of simple examples. There are very few things (problematically speaking) that are harder than writing good, robust, safe multi-threaded code. It's easy to knock up a bit of multi-threaded code in 10 mins; however, because multi-threaded code is (by it's very nature) non-deterministic, it is a git to test! No matter how hard you or your QA team try, there's always a sneaky race condition or priority inversion waiting to catch you out.

The first rule of designing multi-threaded solutions is to try and find another way, the 2nd is to try and find another way and the 3rd is to really try to find another way. If you still think you need to do this then I suggest you check out this: -

http://docs.sun.com/app/docs/doc/816-5137

This is Sun's Multi-threaded Programming Guide. You should read it thoroughly.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20339805
I can also strongly recommend this book...

http://www.oreilly.com/catalog/multithread/

Although it is specific to Win32 programming it does a very good job of discussing all the pitfalls of multi-threaded programming and various design patterns you can adopt to try and avoid them. Most of these principles migrate well to Unix (although the primitives used to achieve them don't).
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 20339863
you might want to refer the following VxWorks APIs, you will ofcourse need to look only at the specific multithreading APIs

http://www.slac.stanford.edu/exp/glast/flight/sw/vxdocs/vxworks/OS_Libraries.htm
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20339882
The kind of problems you can run into with MT programming: -

http://en.wikipedia.org/wiki/Priority_inversion
http://en.wikipedia.org/wiki/Deadlock
http://en.wikipedia.org/wiki/Race_condition

I don't mean to be all doom and gloom, I just want to make sure you know what pain you are potentially letting yourself in for :)

On the up-side, it when it's going well it can be a lot of fun !!!

-Rx.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20339983
It's also worth looking at Boost threads. It provides a nice abstract C++ object model for multi-threaded programming that is cross-platform...

http://www.boost.org/doc/html/thread.html
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 20342121
>>I would like to generate a program which will be used by multiple clients at a time.
I presume that now that you have got an idea of what multithreading means and how ito use it in Solaris, What excatly are you looking for? Are you making a chat server and client? or are you making multithreaded server which cater to different clients at a time?
Best Regards,
DeepuAbrahamK
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 164 total points
ID: 20352306
>>I would like to generate a program which will be used by multiple clients at a time.
That sounds like a client-server, but client-server actually is two programs, a server program which normally is multi-threaded (one main thread managing all other threads and the termination, one 'worker' thread for each client 'connecting to' (using?) the server. The client normally is single-threaded beside it has a GUI. Then the client has an additional worker thread to communicate with the server. A typical client server scenario is:

server:

main thread
  - inits all resources
  - creates one thread for 'accepting' new clients
  - main thread runs infinite loop interuptable by a timeout and/or user request
  - checks client queue for requests
  - processes client requests
  - creates request for client threads

worker thread (accept thread)
  - worker thread waits for incoming clients (e. g. by socket accept on a bound socket in listen mode)
  -  for each client connecting
      - create an additional thread (client thread)
      - pass the connection info to the client thread

client thread
   - waits for requests (handshake, login, authentification) from the client
   - receives requests (messages) from client
   - passes requests from a client to main thread (to a queue)
   - checks input queue for requests from main thread
   - sends messages to clients


client:

main thread:

       - runs GUI
       - on request by user creates a worker thread
       - checks for input messages from server
       - displays server messages
       - passes user requests to worker thread

worker thread:

        - connects to server
        - runs an infinite loop
        - on timeout checks for user message to send to server
        - on timeout checks for messages received from server
        - send messages to GUI thread

You best would use the pthread library as jkr has suggested. For communication sockets are the best choice.

regards, Alex  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question