当前位置: 技术问答>linux和unix
两个子线程之间结束时相互影响了,极度困惑,忘哪位大哥解救,内有完整代码
来源: 互联网 发布时间:2016-10-02
本文导语: 本程序实现的是利用双网卡发送ntp数据包并显示其四个时间戳的的操作,由于调试目前只用一块网卡,所以发送的源地址是相同的。我的问题是给线程1 10个地址进行发包,给线程2 20个地址发包,运行的结果是线程1...
本程序实现的是利用双网卡发送ntp数据包并显示其四个时间戳的的操作,由于调试目前只用一块网卡,所以发送的源地址是相同的。我的问题是给线程1 10个地址进行发包,给线程2 20个地址发包,运行的结果是线程1结束后,会直接导致线程2也结束(线程2此时还没有循环完毕),小弟我百思不得其解啊,有没有哪个大神可以帮忙解决一下,晕死了
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define int8 char
#define uint8 unsigned char
#define uint32 unsigned int
#define ulong32 unsigned long
#define long32 long
#define int32 int
#define long64 long long
#define SIZE 17
#define debug
pthread_t threada,threadb;
//3600s*24h*(365days*70years+17days)
//#define From00to70 0x83aa7
long64 From00to70=2208960000000000;//us(has already redueced 8 hours)
char c[30];
#define src0 "192.168.48.133"
#define src1 "192.168.48.133"
#define NTPPORT 123
long64 firsttimestamp,finaltimestamp;
long64 diftime=0,delaytime=0,reftimestamp=0,oritimestamp=0,recvtime=0,trantime=0,T2=0,T3=0;
double recvtimestamp=0,trantimestamp=0,offset=0;
long recvtimestamphigh=0,recvtimestamplow=0,trantimestamphigh=0,trantimestamplow=0;
typedef struct NTPPACKET
{
uint8 li_vn_mode;
uint8 stratum;
uint8 poll;
uint8 precision;
ulong32 root_delay;
ulong32 root_dispersion;
int8 ref_id[4];
ulong32 reftimestamphigh;
ulong32 reftimestamplow;
ulong32 oritimestamphigh;
ulong32 oritimestamplow;
ulong32 recvtimestamphigh;
ulong32 recvtimestamplow;
ulong32 trantimestamphigh;
ulong32 trantimestamplow;
}NTPPacket;
NTPPacket ntppack,newpack;
void NTP_Init()
{
struct timeval
{
long tv_sec;
long tv_usec;
}tv;
struct timezone tz;
bzero(&ntppack,sizeof(ntppack));
ntppack.li_vn_mode=0x1b;//0|(3
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define int8 char
#define uint8 unsigned char
#define uint32 unsigned int
#define ulong32 unsigned long
#define long32 long
#define int32 int
#define long64 long long
#define SIZE 17
#define debug
pthread_t threada,threadb;
//3600s*24h*(365days*70years+17days)
//#define From00to70 0x83aa7
long64 From00to70=2208960000000000;//us(has already redueced 8 hours)
char c[30];
#define src0 "192.168.48.133"
#define src1 "192.168.48.133"
#define NTPPORT 123
long64 firsttimestamp,finaltimestamp;
long64 diftime=0,delaytime=0,reftimestamp=0,oritimestamp=0,recvtime=0,trantime=0,T2=0,T3=0;
double recvtimestamp=0,trantimestamp=0,offset=0;
long recvtimestamphigh=0,recvtimestamplow=0,trantimestamphigh=0,trantimestamplow=0;
typedef struct NTPPACKET
{
uint8 li_vn_mode;
uint8 stratum;
uint8 poll;
uint8 precision;
ulong32 root_delay;
ulong32 root_dispersion;
int8 ref_id[4];
ulong32 reftimestamphigh;
ulong32 reftimestamplow;
ulong32 oritimestamphigh;
ulong32 oritimestamplow;
ulong32 recvtimestamphigh;
ulong32 recvtimestamplow;
ulong32 trantimestamphigh;
ulong32 trantimestamplow;
}NTPPacket;
NTPPacket ntppack,newpack;
void NTP_Init()
{
struct timeval
{
long tv_sec;
long tv_usec;
}tv;
struct timezone tz;
bzero(&ntppack,sizeof(ntppack));
ntppack.li_vn_mode=0x1b;//0|(3