1

I am reading about const and thread safety in C++11, here is a relevant Stack Overflow question, and here is also a video by Herb Sutter. The word "synchronized" is often mentioned. But what does "synchronized" exactly mean?

For example, the follwing two lines are from Herb's video

"copying from the same object in multiple threads without synchronization" (at 13:40)

"... A const object is fully thread-safe(truly immutable or internally synchronized)" (at 15:03)

Community
  • 1
  • 1
Allanqunzi
  • 3,230
  • 1
  • 26
  • 58

1 Answers1

4

Synchronization means sharing of resources between threads and processes without leading to race around conditions and dead locks.

Without synchronization in 1st statement means that it does not lock the resource and unlock it when it is done.

In second statement he means to say as it is a const object it cannot be modified and is hence perfectly immutable and doesn't need synchronization.

A study on thread synchronization techniques using Mutex and Semaphore will help you better understand why it is needed and how it is done.

Vinay Shukla
  • 1,818
  • 13
  • 41
  • What do you mean by "does not lock the resource and unlock it when it is done"? – Allanqunzi May 15 '15 at 04:48
  • The mutex object referenced by mutex is locked by calling pthread_mutex_lock() and same is called before accessing a shared resource once done you call pthread_mutex_unlock() – Vinay Shukla May 15 '15 at 04:52
  • I still can't get it. Here in the 1st statement Sutter is not mentioning any about mutex. And you say "does not lock" and "unlock", if it "does not lock" how can you "unlock" it? – Allanqunzi May 15 '15 at 15:39
  • @Allanqunzi that is what I am saying please read carefully . Without synchronization means he did not use mutex i.e. he doesn't perform lock and unlock on the resource before using the resource and when it is done respectively. – Vinay Shukla May 17 '15 at 17:46