ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, Can anyone help me..
I am trying to create a message passing structure in a grid .
I have a object switch_p inside which has two struct variables. When I update the elements of the struct from one method and try to take them from another method, g++ compiler complains it cannot read the address:
The Code goes:
typedef struct {
int Status; // -1 = Ideal,1 = Active
int OutputVC;
list<flit_pkt*> flit_buffer;
} Channel;
typedef struct flits {
int destin[2];
int data;
int hops;
int type; // Head =1, Body = 0, Tail = -1
flits *next;
//For the next trail flits in the packets.Tail->next = NULL
} flit_pkt;
I have defined a list of struct flits inside another struct Input_Channel, the compiler doesn't give errors for this syntax.
The two variables of switch class are :
Channel *Input_Channel[];
Channel *Output_Channel[];
//initially these variables are assigned status -1
update_Switch(){
/*This method basically does is takes message stored in the Input_Channel and puts into the output Channel */
......
for(int i=1; i < 10; i++){
if(Input_Channel[i]->Status == 1){
/*This method takes the message stored in output_Channel and passes it to next object of same time*/
for(int i = 1; i < 10; i++){
if(Output_Channel[i]->Status == 1){
switch(i){
case 1:
case 2:
if(Output_Channel[i]->flit_buffer.front()->type == 1 && port_E->eject_message(Output_Channel[i]->flit_buffer.front(), &Output_Channel[i]->OutputVC, 5,6)){
Output_Channel[i]->Status = 1;
// Output_Channel[i]->OutputVC = VChannel;
Output_Channel[i]->flit_buffer.pop_front();
}
else if(Output_Channel[i]->flit_buffer.front()->type == 0 && port_E->eject_message(Output_Channel[i]->flit_buffer.front(), &Output_Channel[i]->OutputVC, 5,6)){
Output_Channel[i]->Status = 1;
Output_Channel[i]->flit_buffer.pop_front();
}
else if(Output_Channel[i]->flit_buffer.front()->type == -1&& port_E->eject_message(Output_Channel[i]->flit_buffer.front(), &Output_Channel[i]->OutputVC, 5,6)){
Output_Channel[i]->Status = -1;
Output_Channel[i]->flit_buffer.pop_front();
Output_Channel[i]->OutputVC = 0;
}
break;
}
The problem here is when I call Update_Switch and the communicate_switch metods simultaneously, the communicate_switch method takes the message stored in Input_Channel[i] and empties the buffer <flit_buffer>, though I am manipulating output_channel[i] from this last method,
and the while the turn of first method comes, since the status is not -1, it tries to read an empty buffer and error comes.This is what I understood, is there somethig else or I am missing something...I would really appreciate anyones help..
Thanks in advance
To get any useful help, I think you will need to do a much better job of asking the question.
You have a vague description of a problem near the top of your post
Quote:
Originally Posted by primenu
g++ compiler complains it cannot read the address:
and you have a vague but apparently contradictory description of the problem near the end of the post
Quote:
while the turn of first method comes, since the status is not -1, it tries to read an empty buffer and error comes.
The compiler is done with its job before the program starts to run. So I expect you didn't really mean the compiler in that first description. But even with that guess, I have no idea what problem you are trying to describe.
In between the two descriptions, you have a lot of code. The lack of code tags makes the whole post unreadable. Learn to use code tags if you want to post code. Edit your first post to add the code tags, so the long code lines don't continue to mess up the whole thread.
It is too much code to expect us to look through with such a confusing description. But it is too little code in the sense that it leaves out key parts without which the parts you posted can't be understood.
Finally, is this a multi threaded program?
Quote:
I call Update_Switch and the communicate_switch metods simultaneously,
What do you mean "simultaneously". Really simultaneously implies multi threaded. To have multiple threads manipulating a complicated linked structure like this ought to require significant use of some kind of lock or semaphore, but I don't see any in your code.
Ok, sorry about the confusion.
First thing is I got runtime errors, that is I have been trying to read an empty buffer, which actually I don't intend to. Input_Channel[] and Output_Channel[] are two properties of an Object, lets say switch here, of struct type Channel. I am using object of another fren class to put in the values into the list <flit_buffer> of the properties Input_Channel.
So, now the 'update' method of the switch class here tries to take the values in the list of Input_Channel[i], and put that into list of Output_Channel[j].
'Communicate' method takes in values stored list of the Output_Channel[i], and sends to another object.
The problem is, When I call the method communicate, instead of emptying list of Output_Channel[i], list of Input_Channel[i] is emptied. And in my code, I have nowhere manipulated the variables Input_Channel[] in the method communicate.
I didn't mean multi-threaded, its just the two methods are called one after another, until all the buffers are empty. I don't know If this makes things clearer. Putting my entire code would make it even messier.
hi, Thanks for pointing out the problem. I guess I made a mistake by declaring the array pointers of undefined size. The problem is solved for now. I will obviously get back in case of other problems. The thing is while trying to explain my problem to you I managed to solve other problems in my code )
You have been real helpful
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.