你能给我一个想法如何实现这一目标吗? [英] Can u give me an idea how to implement this?

查看:69
本文介绍了你能给我一个想法如何实现这一目标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在可行的情况下,您能给我一个想法如何实现吗?
我会遇到什么问题?

我已经编写了一个代码,用于解析从机器接收到的数据.....

我的代码是这样的:-

Can u give me an idea how to implement this,weather it is feasible?
What problems will i face?

I have made a code for parsing data that i received from the machine.....

My code is something like this:-

int main()
{
   // Initialize Winsock

   // Attempt to connect to server(machine from which i will get data)
   {
      //Run the ioctlsocket() command
      //Run the setsockopt() command
      // Connect to server.
   }
   
   //create thread
    while(1);
}

//Thread defination()
{
   while(1)
   {
      //send data to machine
      //receive data from machine
      
      if received bytes is equal to,what we want then call
      //function to parse the data and store it in a file
   }
}


我要做的是:-

使用此代码可在大约100台计算机上运行.
我将从数据库中读取机器的IP和端口.

我正在考虑这样做:
我将编写一个查询,该查询将返回数据库中ip和端口的no(count).
然后根据计数,我将为每个ip和端口创建线程,每个线程将包含另一个线程,该线程将用于发送和接收数据.

这是FINE解决方案吗?
我必须使用任何信号量,互斥体吗?
我将面临什么问题?


What i have to do is:-

Use this code to run on approx 100 machine.
I will read the ip and port of the machine from database.

I am thinking o do it like this:
I will write a query which will return me the no(count) of ip and port in the database.
Then depending upon the count i will make thread for each ip and port,each thread will contain one more thread that will be used for sending and receiving data.

Is this the FINE solution?
Do i have to use any semaphore,mutexes?
What problems will i face?

推荐答案

报价:

我必须使用任何信号量,互斥体?

Do i have to use any semaphore,mutexes?


除非您拥有线程之间共享的资源(而且似乎没有这样做),否则您不需要任何形式的锁定,因为没有什么可锁定的.

我不太确定我是否了解您要执行的操作,但除此之外,我看不出您的计划有明显的错误.


Unless you have resources that are shared between threads (and it does not appear that you do) then you don''t need any form of locking, because there is nothing to lock.

I''m not quite sure I understand what you''re trying to do, but I don''t see anything obviously wrong with your plan otherwise.


这篇关于你能给我一个想法如何实现这一目标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆