B
Bob
I have an odd situation that I didnt expect, so I probably dont
understand enough which is why Im asking here.
I have created a multithreaded TCP server which has the
following buffer in each thread:
tcpThread.h:
unsigned char in_buffer[MAX_TCP_BUF];
tcpThread.cpp:
size_t n = read(fd, in_buffer, MAX_TCP_BUF];
PROBLEM:
This is under linux. I only have 2 clients connected, so each has its
own
pthread() of the above, but I see in_buffer[] occasionally getting
characters
and/or leftover characters from the other client in the 'in_buffer'.
I changed the code to make in_buffer[] a static array in the .cpp file
instead and I believe that has solved the problem, but I would like to
further understand the problem.
I had thought that having it in the .h file just meant that as each
thread
was created, it had its own address of the array, but apparently thats
not the case?
thanks in advance.
understand enough which is why Im asking here.
I have created a multithreaded TCP server which has the
following buffer in each thread:
tcpThread.h:
unsigned char in_buffer[MAX_TCP_BUF];
tcpThread.cpp:
size_t n = read(fd, in_buffer, MAX_TCP_BUF];
PROBLEM:
This is under linux. I only have 2 clients connected, so each has its
own
pthread() of the above, but I see in_buffer[] occasionally getting
characters
and/or leftover characters from the other client in the 'in_buffer'.
I changed the code to make in_buffer[] a static array in the .cpp file
instead and I believe that has solved the problem, but I would like to
further understand the problem.
I had thought that having it in the .h file just meant that as each
thread
was created, it had its own address of the array, but apparently thats
not the case?
thanks in advance.