os-70-350

os-70-350 Commit Details


Date:2014-01-11 17:50:10 (11 years 7 months ago)
Author:Natalie Adams
Branch:master
Commit:109ffa1f3c5bb10f2a8c89c710c9dbda31bc6eca
Parents: 055dd047a33cc84834c2963068af1d741902b764
Message:making sample simpler

Changes:

File differences

racecondition-linux/main.c
1212
1313
1414
15
16
15
1716
1817
1918
......
2322
2423
2524
26
27
28
29
30
31
3225
3326
3427
while (1)
{
while (counter == BUFFER_SIZE - 1);
buffer[counter + 1] = rand() % 20 + 1; // yes I know rand is not thread safe - I just need a way to demonstrate a producing/consuming problem - using the same number doesn't help.
buffer[counter + 1] = rand() % 20 + 1;
printf("PRODUCER value = %i counter = %i\n", buffer[counter + 1], counter + 1);
counter++;
}
while(1)
{
while (counter == -1);
if (buffer[counter] == 0)
{
printf("%i\n", buffer[counter]);
printf("Attempting to consume an element that was already consumed counter = %i\n", counter);
exit(1);
}
printf("CONSUMER value = %i counter = %i\n", buffer[counter], counter);
buffer[counter] = 0;
counter--;

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.35837s using 14 queries.