473,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

parallel, concurrent server with Boost::thread

Greetings to everyone...
This is my first message in this forum and I have a very short experience in C++.
This said, I would like to setup a server that accept strings from many clients, elaborates those strings and send them back to each client, in the correct way.

The elaboration is done through and external program, that I have to call with "execl", this is compulsory. So this program is a shared resource that should be "mutexed", in order to avoid wrong order in messages.

With a simple C syntax, I would like to so something like this:

Expand|Select|Wrap|Line Numbers
  1. //parent process
  2. while(1){
  3.         int conn=accept(listen_sd,........);
  4.  
  5.         if( fork()==0 ){  //child process
  6.              close(listen_sd);
  7.              //reading from conn
  8.              //elaborating received data, through a common resource, to be "mutexed"
  9.              //sending results to conn
  10.         }
  11.  
  12.         //parent process
  13.         close(conn);
  14. }
The basic idea is to open a new thread for each new client connected, and every thread has to be independent and to be synchronized to the common resource.

Is there someone so kind and powerful who could help me in a practical and easy way?
(I am sorry but I'm using C++ only for 4 month and many things are still so hard)

Thank you all for your attention
EMA
Jun 8 '07 #1
3 2791
gpraghuram
1,275 Expert 1GB
HI,
You can use posix multithraeding.
You have to create a detached thread for each client as soon as you accept the connection.

Hope this helps
Raghuram
Jun 8 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
This is not a C++ issue. This is a multithreading issue.

I suspect you will call pcreate_thread and fork your process on that thread.

I would start with a book on multithreading.
Jun 8 '07 #3
Thank you for your replies...
Actually I am still studying C++ (or C for networking), I am mainly learning through examples because I have no time to study deeply...
I would like to say that I could perfectly setup such a system in Java, it would be pretty easier, but I cannot use it here...

So my problem is not just "multithreading" itself, but how to realize it in a real way in C++, if possible.
I though to Boost::thread for there is some "simple" example, I took a look to Posix threads but they seems really complicated for me...

Can you suggest me some practical application to manage synchronization, in C++?

Thank you very much for you patience...
Jun 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dingounan | last post by:
how to compile boost.thread,and set it? I have trouble. platform: windows XP compiler: Borland C++ Compiler 5.5.1 commandline tools thanks.
1
by: deluded.soul | last post by:
Hi everyone, I am trying to use the boost multithreading library. I am having a problem as the join() function for the thread never returns. I am using a boolean variable to indicate when the...
4
by: Lighter | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; using namespace boost; void hello() { cout << "Hello world, I'm a thread!" << endl; }
5
by: linyanhung | last post by:
I used a boost multi thread in VS 2005 on a Duo Core PC, and made a two thread process. The code is something like this: #include <boost/thread/thread.hpp> void fun1() { //do something
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
4
by: Gary Wessle | last post by:
Hi given the Boost thread example here http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/thread/example/thread.cpp the code below attempts to run the example thread while...
1
by: Miroslaw Makowiecki | last post by:
Is it boost.thread library have a ability by next of its I is allowed to find out what it is running? How do it? Thanks in advice.
2
by: Chameleon | last post by:
Why this strange output? Why so many d'tor calls? The code: ---------------------------------------------------------- #include <cstdio> #include <boost/thread/thread.hpp> class A {
2
by: Hans Mull | last post by:
Hi! I'm experimenting with boost::thread. I have a GUI application with a slot function: void someFunction(){...} void Frame::OnOkButtonClick(...) { switch(someInteger) { case 0: break
3
by: Lars Uffmann | last post by:
I have this wxWidgets OnButtonClick event handler, that apparently holds a lock on all widgets in my form, but this event handler is supposed to end a thread in the background - while that thread...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.