Author |
Message |
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sat Oct 24, 2009 4:10 pm Post subject: [C++] Stupid bug... [SOLVED] |
|
|
|
|
We're making this program for school, it has to simulate a TCP/IP protocol using UDP. Basically a couple of networking layers, each has its own thread, two queues for requests (from layer above) and indications (from layer under).
We're having this very weird bug, the queue works fine, but at some point, I get memory access violation error... It appears that the queue object in the layer is... moved?! When I put a watch on 'this' while in the queue, it's like 0x00000008 or something like that, which is nowhere near a good pointer.
I used the linkedlist from mervbot core, but I also had the issue with some STL queue I tried.
I can't figure out the problem... I'm hoping some of you guys could help me out
The source has a bunch of files and stuff, but I'm sure you'll find a way through it all... The server project works fine, but the client one gives the exception after sending a request to a layer.
Have fun :/ and thank you in advance
<attachment removed> _________________ (Insert a bunch of dead links here)
Last edited by Samapico on Mon Oct 26, 2009 4:56 pm, edited 2 times in total |
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Sun Oct 25, 2009 8:36 am Post subject: |
|
|
|
|
For some reason queue.cpp is a 0 byte file in that rar you uploaded _________________ Rediscover online gaming. Get Subspace | STF The future...prehaps
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Oct 25, 2009 1:22 pm Post subject: |
|
|
|
|
hmm, it's not even part of the project, the _queue type I used is in types.h/cpp, but I think when I uploaded it it's actually using a _linkedlist , also in types.h/cpp
Attached proper arborescence of both projects in case you're not using visual studio; a couple of files in the .rar are not used
Project arborescence
server.png - 11.21 KB
File downloaded or viewed 170 time(s)
Project arborescence
client.png - 11.04 KB
File downloaded or viewed 151 time(s)
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Oct 25, 2009 5:33 pm Post subject: |
|
|
|
|
i was able to go one more step forward, somehow...
I was able to send a message from the client to the server, the server network layer received it, but then I get the same crash...
Worse part is that i have no idea what I did to fix it... I moved some stuff around, but none of these things should change anything >=(
I guess I'll check the diffs through SVN and test a bunch of stuff...
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Sun Oct 25, 2009 8:28 pm Post subject: |
|
|
|
|
I've found your problem samp.
The linked list you are using isn't threadsafe. I think this might be the problem.
So when two threads enter the "append" method at the same time, they interact in an unpredictable way. If you step into it, and look at the other thread in visual studio you'll see they are both in the same method.
http://img193.imageshack.us/img193/9527/forsamp.jpg
You need to use a threadsafe class or make it thread safe, using mutex's or something similar. If two threads interact like this, the result is unpredictable, which is why sometimes it works and sometimes not.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Oct 25, 2009 9:57 pm Post subject: |
|
|
|
|
But... aren't these 2 different instances of the list???
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Mon Oct 26, 2009 6:45 am Post subject: |
|
|
|
|
Hmm, if there two different instances they shouldn't interact... I'll take another look at it when i'm more awake, it was just after midnight on a sunday -_-
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Oct 26, 2009 1:23 pm Post subject: |
|
|
|
|
I also tried using critical sections while anything is appended or removed from the list, but that didn't work (you can still see these sections commented out)
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Mon Oct 26, 2009 2:55 pm Post subject: |
|
|
|
|
I had another look and got no closer, i tried the critical section thing too...The thing that makes me think its a threading issue is because if i put a breakpoint on the "Append" Method and step though it slowly, i dont get the error, but if i run it at full speed it crashes.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Oct 26, 2009 3:07 pm Post subject: |
|
|
|
|
it doesnt crash on the first append... break at the 2nd .addrequest in c_main.cpp, and go slow, it should crash
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Oct 26, 2009 4:34 pm Post subject: |
|
|
|
|
F*************************** &*"/$6Y&*"$?&*
I FORGOT TO USE THE ATTACHLAYERS GODDAMNIT
It makes sense now... THANK YOU
I remember thinking that I should check if I did attach the layers, but I was probably sleeping or something, and I completely forgot...
|
|
Back to top |
|
|
|