473,378 Members | 1,412 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.

Threads communcation in network programming

QQ
Hello I am a beginner for network programming.
Now I am trying to implement some function like this

I am keep listening to a port, when I get some message, I will have
some corresponding response. And the same time, I can send out message.

So I put the listening function in the child process.
My question is when I receive some packet, how can I send signal to the
main thread.
Thanks a lot!

Nov 14 '05 #1
1 1342

"QQ" <ju****@yahoo.com> wrote in message

I am keep listening to a port, when I get some message, I will have
some corresponding response. And the same time, I can send out message.

So I put the listening function in the child process.
My question is when I receive some packet, how can I send signal to the
main thread.

You go beyond ANSI C, because there is no signalling / interrupt mechanism.
These are often provided as platform-specific calls.

However ANSI C does provide "volatile". This flags a variable as being able
to be altered by an outsode process, such as your child.

So a simple scheme would be

global variables:

struct packet data;
volatile int semaphore;

/* child */

wait till packet comes.
if semaphore not "clear" you have a problem. Maybe busy idle checking it
until it goes to "clear".
set semaphore to busy.
write data to global structure
set semaphore to "data ready"
wait till next packet comes.

/* main process */
every so often, check semaphore.
if it is set to "data ready" set semaphore to "busy", other wise go back to
main loop
read data into own structure
set semaphore to clear.
go back to main loop.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Parahat Melayev | last post by:
Hi I am programming a multi-threaded asyncronous server with .NET But when systems thread count reaches to 1350 system can't respond. Simply my design is creating a Reading Thread after...
5
by: KevinGPO | last post by:
Two quick queries: 1. I have programmed a little network performance monitor. It monitors a set of remote hosts over a network. It gets the CPU statistics and all gets collected at one of the...
3
by: mphanke | last post by:
Hi, I would like to implement a windows service which forks a configurable number of threads which all siten to the same port and reply to requests of different clients. How would I implement...
9
by: Arafangion | last post by:
Hello, recently I've been trying to figure out how the heck to just destroy a thread. I have since rewritten the code in question, but what I was trying to do was to use the .Abort() method, but...
6
by: Alexander Walker | last post by:
Hello Is it inefficient to create an application that has many threads that individually may do a small amount of work over a given period of time as opposed to an application that has a...
11
by: vzaffiro | last post by:
Does the magic number of 25 only apply to the thread pool? Does it also apply to manually creating threads?
7
by: gel | last post by:
Hi all I am attempting to understand threads to use in a network app which I am writing. The part that I am going to use threads on is run on the clients/workstations. I will monitor all...
13
by: barcaroller | last post by:
If this is not the right newsgroup for "C++ threads", please consider this message off-topic and ignore it. --------------------------------------------- I am writing a multi-threaded application...
2
by: Richard Cranium | last post by:
Hello, I have an interesting problem: I've got one thread in my program meant to maintain a timing subsystem and to do network I/O. It uses the select() system call to either wait for I/O or...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.