Open grisharav opened 5 years ago
I think you're right. A simple fix for this would be to assign the crc_table
onlly at the end of the function BuildCRCTable
instead of initializing it at the begining, i.e.
static void BuildCRCTable ()
{
uint polynom = 0xEDB88320;
//crc_table = new uint[256];
var table = new uint[256];
for (int i = 0; i < 256; i++) {
uint c = (uint)i;
for (int k = 0; k < 8; k++) {
if ((c & 0x00000001) != 0x00)
c = polynom ^ (c >> 1);
else
c = c >> 1;
}
//crc_table[i] = c;
table[i] = c;
}
crc_table = table;
}
Will probably work, I would simply make crc_table
a Lazy<uint[]>
Good idea! This be even cleaner.
When I run in parallel lots of
File.Create(...)
calls (on different paths) I sometimes geton the first file
I believe this is due to unsafe code in File.cs:
in the if (crc_table==null) check, multiple threads can start building the crc table and corrupt the results.