c++ - Pthreads and dynamic memory -


my thread routine looks this

void * dowork(void * args) {     char* ptr = new char[25];     memset(ptr, 0, sizeof(ptr));     // operations ptr     // if call delete[] ptr } 

i've initialized 5 threads. questions,

  1. is thread safe?
  2. which thread owns memory?
  3. will ptr re-initialize every time new thread processes dowork? if yes, happen memory allocated earlier?
  4. what if delete[] ptr used @ end of dowork?

  1. the ptr local pointer no other thread interfere long not communicate pointer thread.

  2. two threads running function allocate 1 char[25] array each. thread not owner rather process owns it.

  3. ptr re initialize , old memory not deleted on thread join. if no delete used leak memory.

  4. delete[] use yes.

to explain ptris allocated operative system , every call of new allocate new pointer operative system. value of ptr ie points, local stack variable hence local thread , no other threads can value long not communicated.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -