J
JAM
Donis Marshal book about C# language states that array access in C# is
not thread safe, but he does not elaborate on this to any detail. I
was wondering if it is not thread safe for all operations ? In my
program I have quite large array in main thread that I would like to
access from children threads for READ ONLY operation. My application
is solving a challenging puzzle by brute force and to speed up the
solver I have divided the task between available CPU cores using
threads. The problem is that to solve the puzzle they need to access
multiple times this array prepared beforehand in main thread. They all
will use read only access. I can't use lock statement because, that
would defy the intent of solving puzzle simultaneously in multiple
threads doing basically the same thing and certainly I would hate to
create copy of the same array for each thread, because it is quite
large.
Assuming, that read only access will turn out to be thread unsafe, is
StackAlloc and pointers another possible solution ?
Side question would be if StackAlloc and pointers (I'm guessing) are
not using boundary checking and are referring to memory directly
instead of through handle, should that have additional benefit of
slightly faster code ?
JAM.
not thread safe, but he does not elaborate on this to any detail. I
was wondering if it is not thread safe for all operations ? In my
program I have quite large array in main thread that I would like to
access from children threads for READ ONLY operation. My application
is solving a challenging puzzle by brute force and to speed up the
solver I have divided the task between available CPU cores using
threads. The problem is that to solve the puzzle they need to access
multiple times this array prepared beforehand in main thread. They all
will use read only access. I can't use lock statement because, that
would defy the intent of solving puzzle simultaneously in multiple
threads doing basically the same thing and certainly I would hate to
create copy of the same array for each thread, because it is quite
large.
Assuming, that read only access will turn out to be thread unsafe, is
StackAlloc and pointers another possible solution ?
Side question would be if StackAlloc and pointers (I'm guessing) are
not using boundary checking and are referring to memory directly
instead of through handle, should that have additional benefit of
slightly faster code ?
JAM.