cout and perror messages in wrong sequence [message #1818967] |
Fri, 03 January 2020 11:31  |
Eclipse User |
|
|
|
Need to synchronize cout and perror inTO correct code sequence.
I have been searching for an answer to this debugging dilemma.
I am using BOTH cout and perror to trace thru my code.
Both are output to Eclipse console in correct sequence when run on single core processor ( Raspberry Pi) so the opinion of another forum goes.
The messages outputs are hopelessly garbled / out of sequence when I run C++ code on 4 core , local , processor. Apparently cout and perror are run on different cores and not in the sequence expected.
I cannot argue with this multicore (solution) opinion -, but it seems odd.
I like to use perror since it outputs error messages , when available, so suggestion to ditch perror is not a solution. So is usage of cerr.
I did try suggested ios_base::sync_with_stdio(); , it changed the outputs just placing perror messages ahead of cout messages - again in one block ( see attached ).
The attached code snippet and full output of the app should clarify what I am against.
This is "under construction " code posted with intend to demonstrate the issue, I am not soliciting comments on my code style.
int result = -1;
ios_base::sync_with_stdio();
cout << "Server waits for a client request." << endl;
C_SOCKET SERVER;
if(SERVER.AllocateSocket() == 0 )
{
ios_base::sync_with_stdio();
cout << "STOP @line " << __LINE__ << endl;
ios_base::sync_with_stdio();
perror (" SUCCESS SERVER.AllocateSocket()");
}
else
perror (" FAILED SERVER.AllocateSocket()");
Server waits for a client request.
TRACE TODO Auto-generated constructor stub
TASK @line 49
function C_SOCKET
STOP @line 51
TRACE allocate a socket
TASK @line 252
function AllocateSocket
STOP @line 254
perror message should be here
socket allocated SUCCESS: Success
perror message should be here
STOP @line 114
TRACE set the connection parameters (who to connect to)
TASK @line 176
function Bind
STOP @line 178
TRACE bind socket to port 1 of the first available local bluetooth adapter
TASK @line 191
function Bind
STOP @line 193
TRACE bind socket to port 1 of the first available local bluetooth adapter
TASK @line 217
function Bind
STOP @line 219
TRACE put socket into listening mode - single queue
TASK @line 136
function SetupListen
STOP @line 138
TRACE STOP
TASK @line 133
function main
STOP @line 135
TRACE accept one connection - single queue
TASK @line 114
function SetupAccept
STOP @line 116
block of perror messages AFTER the run stops
DOES NOT BELONG HERE
socket allocated SUCCESS: Success
SUCCESS SERVER.AllocateSocket(): Invalid argument
bind to local SUCCESS: Invalid argument
SUCCESS SERVER.Bind(): Invalid argument
set into listen mode SUCCESS: Invalid argument
SUCCESS SERVER.SetupListen(): Invalid argument
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04804 seconds