-1

When I reading references about calloc in calloc reference in cppreference ,I found the following tips which I didn't get.

  • calloc is thread-safe: it behaves as though only accessing the memory locations visible through its argument, and not any static storage.

  • A previous call to free or realloc that deallocates a region of memory synchronizes-with a call to calloc that allocates the same or a part of the same region of memory. This synchronization occurs after any access to the memory by the deallocating function and before any access to the memory by calloc.

Can you give me examples to help to understand it?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
waterd
  • 603
  • 1
  • 7
  • 23

1 Answers1

1

It just means that calloc will work just fine if you use it in a multi-threaded environment (lots of threads running at the same time, and all allocating or releasing or reallocating memory like crazy is no problem).

Since not all C and C++ functions make that kind of guarantee, it needs to be mentioned in the documentation. Usually you should assume that when thread safety isn't mentioned, it isn't thread safe.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • I know a thing called **thread-safe** and I can pick it out when someone is talking about it,but I had little multi-thread programming practice.BTW,you forgot to tell me your opinions about the second tip in my question. – waterd Aug 28 '14 at 11:55