What you should do is
1 Not free the data at line 31, you can not know that the thread has not finished with it. Test by adding a short sleep in print_thread_id
Then either
2 Use pthread_join to detect when the thread has finished running then free the memory.
or (and my personal choice)
3 Assign ownership of that memory to the thread and free the memory in the thread function itself when the thread has finished with the data
Banfa
Practically a Master Poster
695 posts since Mar 2010
Reputation Points: 508
Solved Threads: 109
Skill Endorsements: 5