• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

multithreading in C++ using solaris

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
shankarraj
Asked:
shankarraj
  • 4
  • 2
  • 2
  • +3
3 Solutions
 
trinitrotolueneDirector - Software EngineeringCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
Multithreading is closely related to operating system. So, which one are you using?
0
 
jkrCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jaime OlivaresSoftware ArchitectCommented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
>> 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
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
Deepu AbrahamR & D Engineering ManagerCommented:
>>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
 
itsmeandnobodyelseCommented:
>>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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now