0

I searched all over the internet about it (Wikipedia included),but all tell the same theoretical thing in varying degree of complexity in their choice of technical jargon,that race conditions arise when two processes etc race to read/write data and one might be trying to read when other is attempting to alter it.

So far so good as far as learning it by rote and answering this theoretically in an examination is concerned.But I really want to understand it,with the core and details in plain English,and especially with a simple C program that illustrates it.A little C program will make it more than anything,especially since I want to know it in context of C.Can you kindly put up a plain-English explanation with a little C program?

PS: This line taken from the description of a string library function minutes back made me realize again the need to really understand data race condition.

The point where the last token was found is kept internally by the function to be used on the next call (particular library implementations are not required toavoid data races).

Thokchom
  • 1,554
  • 3
  • 15
  • 31
  • There's a very simple example of two processes trying to add 1 to a variable in the Wikipedia entry. Doesn't that help? – Barmar May 16 '13 at 04:53
  • I am afraid I had checked that question end to end before posting my question as it didn't help me. – Thokchom May 16 '13 at 04:53
  • The first answer gives an example in C, which is exactly what you asked for. Between the Wikipedia example and that one, it doesn't get much simpler. – Barmar May 16 '13 at 04:55
  • 2
    If you want more help, you'll have to explain *why* the wikipedia example didn't help you. What don't you understand? – Blorgbeard May 16 '13 at 05:02
  • @Blorgbeard It has no accomanying C code,it generally does for such things,ie carry code in C/C++,among other language snippets. – Thokchom May 16 '13 at 05:07
  • @Blorgbeard And is a detailed understanding of thread necessary to grasp it in C?Like the line I have taken from the description of that library function above,it seems like it talks of "normal progams" as well,not multi-threaded essentially.What does `The point where the last token was found is kept internally by the function to be used on the next call (particular library implementations are not required toavoid data races).` mean? – Thokchom May 16 '13 at 05:08
  • It seems that you take this quote from this site: http://www.cplusplus.com/reference/cstring/strtok/ For what I understood, it is saying that whoever is implementating this function is not required for them to take any concerns about race conditions. In linux, its manual pages says that: `The strtok() function uses a static buffer while parsing, so it's not thread safe. Use strtok_r() if this matters to you.` – Amadeus May 16 '13 at 05:25
  • @TomásBadan That helped...but umm.....can you please define "static buffer" a single line? – Thokchom May 16 '13 at 05:28
  • A buffer that you use for everything. Or in other words, a buffer that is not allocated and neither deallocated at runtime, except, maybe, for its first use time – Amadeus May 16 '13 at 05:32

0 Answers0