• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to share a 2d integer array  RSS feed

 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to share an array of integer among a parent and all its children and synchronise them. Only the children will process the array. Mutual exclusion is needed to ensure that they do not change the same array element. I tried this.
It gives error assignment to expression with array type;
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra koranga wrote:
It gives error assignment to expression with array type;


I am assuming "error" means compiler error? And that it is at line 5? ... if not, please provide the full compiler error messages.

As for line 5, obviously, that is not a valid array declaration. You are missing the data type.

Henry
 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No its just a typo in this code. What I want is I have a 2d array of character pointers  for eg char *queue [10][10]. The parent fills first column of this array. Then I wish to share it among the children for processing. Children may fill more elements in this array. What is the best way to do it.One way I can think of is to use shmget() function to request a shared memory and then copy this array to the shared memory in parent. Is there any better way to do this?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra koranga wrote:Is there any better way to do this?


IMHO, the two easiest way to share live data structures are via shared memory, or via mmap files. I came from a SunOS background, so prefer the latter, but they both should be equally fine (in fact, under the hood, with many implementations, they route to the same code in the OS).

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!