473,405 Members | 2,185 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,405 software developers and data experts.

pointer be changed strangely

I use gdb to trace the following code and find "howlong" is changed
strangely.

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
//print howlong. howlong=0x8083258
//then step into select()
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
//print howlong. howlong=0x0
return ::select(nfds_,r,w,e,howlong);}

There is no code between the change of "howlong". Why this happen?

Jul 23 '05 #1
10 1467
el******@gmail.com wrote:
I use gdb to trace the following code and find "howlong" is changed
strangely.

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
//print howlong. howlong=0x8083258
//then step into select()
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
//print howlong. howlong=0x0
return ::select(nfds_,r,w,e,howlong);}

There is no code between the change of "howlong". Why this happen?


In Linux (and some other systems) the timeout value to "select" is
changed to indicate how much time was left on the timer. The Single
Unix Specification (and probably POSIX, though I don't have a copy of
the standard to check) allow this behavior. To be portable, you should
consider the value of the timeout after a select to be undefined.

-Alan
Jul 23 '05 #2


Alan Johnson wrote:
el******@gmail.com wrote:
I use gdb to trace the following code and find "howlong" is changed
strangely.

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
//print howlong. howlong=0x8083258
//then step into select()
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
//print howlong. howlong=0x0
return ::select(nfds_,r,w,e,howlong);}

There is no code between the change of "howlong". Why this happen?

In Linux (and some other systems) the timeout value to "select" is
changed to indicate how much time was left on the timer. The Single
Unix Specification (and probably POSIX, though I don't have a copy of
the standard to check) allow this behavior. To be portable, you should
consider the value of the timeout after a select to be undefined.


I don't think this is the issue. He's seeing his "howlong" value
change BEFORE calling ::select(). Currently, its not apparent to me
why this would be.
-Alan


Jul 23 '05 #3

<el******@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I use gdb to trace the following code and find "howlong" is changed
strangely.

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
//print howlong. howlong=0x8083258
//then step into select()
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
//print howlong. howlong=0x0
return ::select(nfds_,r,w,e,howlong);}

There is no code between the change of "howlong". Why this happen?


What's your *real* code look like? You don't show the "print" statement
you're using to get those values. (Is that some gdb feature?) One thing I
do see, which may or may not be related, is that you're setting a value for
howlong in the waitFor function, but that change is only occurring to the
local copy of that pointer. It will not change the value of the poitner
passed to waitFor unless you make it a reference (or pointer) to a pointer.
Perhaps this problem is causing gdb (a tool I know nothing about) to show
you the wrong "howlong" variable. I know some debuggers can give you
misleading information when you've got multiple variables with the same
name. In any case, if you want that howlong parameter to change in the
calling function (and not just for a local copy), then make it timeval*&
instead of just timeval*. Likewise if select is going to change it (and you
want waitFor to see that change).

-Howard


Jul 23 '05 #4
Yes!"He's seeing his "howlong" value change BEFORE calling
::select(). " What cause this is what I want to know.

Jul 23 '05 #5
Here is the code.
applMain() {
StringList positional;
CSTR path=RunEnv::unixPath(*main,&positional);
if(path==0) exit(1);

PktCtlClient client(positional);

CmDispatch& disp=CmDispatch::instance();
for(;;) {disp.dispatch();}
exit(0);}

void CmDispatch::dispatch() {
dispatch(0);}

bool CmDispatch::dispatch(timeval* howlong) {
int nfound;
static timeval timeout;
if(anyReady()){howlong=&timeout;}
nfound=waitFor(howlong);
notify();
return nfound>0;}

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
return ::select(nfds_,r,w,e,howlong);}

timeval *TimerQueue::calculateTimeout(timeval* howlong) const {
static timeval timeout;
if(isEmpty()) return howlong;
timeval curTime=currentTime();
timeval ealiest=earliestTime();
if(ealiest>curTime) {
timeout=ealiest-curTime;
if(howlong==0|| *howlong>timeout) {
howlong=&timeout;}}
else {
timeout=TimerQueue::zeroTime();
howlong=&timeout;}
return howlong;}

Jul 23 '05 #6
Howard, thank you. I use printf() statement instead of gdb print
function to display the "howlong" value. The value doesn't change. So
this issue maybe a problem of gdb.

Jul 23 '05 #7


el******@gmail.com wrote:
Here is the code.
applMain() {
StringList positional;
CSTR path=RunEnv::unixPath(*main,&positional);
if(path==0) exit(1);

PktCtlClient client(positional);

CmDispatch& disp=CmDispatch::instance();
for(;;) {disp.dispatch();}
exit(0);}

void CmDispatch::dispatch() {
dispatch(0);}

bool CmDispatch::dispatch(timeval* howlong) {
int nfound;
static timeval timeout;
if(anyReady()){howlong=&timeout;}
nfound=waitFor(howlong);
notify();
return nfound>0;}

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
return ::select(nfds_,r,w,e,howlong);}

timeval *TimerQueue::calculateTimeout(timeval* howlong) const {
static timeval timeout;
if(isEmpty()) return howlong;
timeval curTime=currentTime();
timeval ealiest=earliestTime();
if(ealiest>curTime) {
timeout=ealiest-curTime;
if(howlong==0|| *howlong>timeout) {
howlong=&timeout;}}
else {
timeout=TimerQueue::zeroTime();
howlong=&timeout;}
return howlong;}


Is this program multithread?

Regards,

Jul 23 '05 #8


el******@gmail.com wrote:
Here is the code.
applMain() {
StringList positional;
CSTR path=RunEnv::unixPath(*main,&positional);
if(path==0) exit(1);

PktCtlClient client(positional);

CmDispatch& disp=CmDispatch::instance();
for(;;) {disp.dispatch();}
exit(0);}

void CmDispatch::dispatch() {
dispatch(0);}

bool CmDispatch::dispatch(timeval* howlong) {
int nfound;
static timeval timeout;
if(anyReady()){howlong=&timeout;}
nfound=waitFor(howlong);
notify();
return nfound>0;}

int CmDispatch::waitFor(timeval* howlong) {
int nfound=-1;
for(;nfound<0;) {
CmFdSet& r=onRead_->onSelects();
CmFdSet& w=onWrite_->onSelects();
CmFdSet& e=onExcept_->onSelects();
howlong = queue_->calculateTimeout(howlong);
nfound=select(r,w,e,howlong);
if(nfound<0) {handleError();}}
return nfound;}

int CmDispatch::select(CmFdSet& r,CmFdSet& w,CmFdSet& e,timeval*
howlong) {
return ::select(nfds_,r,w,e,howlong);}

timeval *TimerQueue::calculateTimeout(timeval* howlong) const {
static timeval timeout;
if(isEmpty()) return howlong;
timeval curTime=currentTime();
timeval ealiest=earliestTime();
if(ealiest>curTime) {
timeout=ealiest-curTime;
if(howlong==0|| *howlong>timeout) {
howlong=&timeout;}}
else {
timeout=TimerQueue::zeroTime();
howlong=&timeout;}
return howlong;}


I apologize if this post is duplicated.

I just need to know whether your program is multithread app or not?

Regards,

Jul 23 '05 #9

<el******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Howard, thank you. I use printf() statement instead of gdb print
function to display the "howlong" value. The value doesn't change. So
this issue maybe a problem of gdb.


Sounds like it's working correctly, then. Glad I could help.

-Howard
Jul 23 '05 #10
It's sigle thread.

Jul 23 '05 #11

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

Similar topics

4
by: xuatla | last post by:
Hi, I have a class class myType { private: int size; double *elem; .....
0
by: ellre923 | last post by:
I use gdb to trace the following code and find "howlong" is changed strangely. int CmDispatch::waitFor(timeval* howlong) { int nfound=-1; for(;nfound<0;) { CmFdSet& r=onRead_->onSelects();...
16
by: fix | last post by:
Hi all, I am new to C and I just started to program for a homework. I included my code down there. It is a fraction "class". I declared the Fraction struct, tried to create some invalid fraction,...
10
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr;...
40
by: Foobarius Frobinium | last post by:
Please review this guide for clarity, accuracy, etc. so I can hopefully compile a very good tutorial on how to use pointers in C, including advanced topics, that is easy to follow and exposes the...
5
by: Cancerbero | last post by:
Hi (first, excuse me for my bad english) As I know, the semantics for typedef is: typedef A B; I think this makes B a synonym of A, where A is an existing data type. Is that right? Based...
19
by: George | last post by:
Hi all. How can I check and return an error on a constructor that receives a pointer as a parameter and the parameter is null. Is there any possibility to return an error? or do I have to create...
4
by: mathon | last post by:
Hello, if i have these two declarations: 1)const int * test; and 2)int* const test;
7
by: william | last post by:
My question is: Specific memory block where my pointer pointing to changed strangely, seemingly that no statement changed it. Here are two examples I got: ***********1***************** I was...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.