login about faq

Below function used to get CkEmail pointer. CkEmail* ckMail = conn.FetchEmail(i, true, output);

Pass ckMail pointer to another thread to save email contents to database. CkEmail *ckMail = (CkEmail *)pVal; // sure that its same pointer which is passed.

During accessing this ckMail pointer application is crashing. CkString str; ckMail->get_Body(str); // application crashes.

Above source code is written into the DLL and Used settings. Multi-threaded Debug DLL (/MDd), Visual studio 2005 (SP2) ChilkatDbgDll.lib, ChilkatRelDll.lib -- create date (12/12/12)

asked Mar 18 '13 at 05:22

Mehul's gravatar image


edited Mar 20 '13 at 07:25

My guess is that you are passing the pointer to a background thread, but then in the foreground thread you are deleting the object. Therefore, the background thread has a pointer to an already-deleted object. Make sure this isn't the case.


answered Mar 20 '13 at 08:26

chilkat's gravatar image

chilkat ♦♦

edited Mar 20 '13 at 08:26

No, I am clearly debugging application verifying pointer value in debug wizard. Using pointer getting data and ultimately deleting happen in the background thread only. Foreground thread reads emails from mailbox and pass pointer to background thread and its work finish.

(Mar 21 '13 at 06:50) Mehul

The fact that it's running in a background thread should make no difference. If a problem arises ONLY because of multi-threading, then it could be caused by one of the following:

1) The object is not thread-safe. Thread-safe means that it's OK for multiple threads to be making calls simultaneously on the same object instance. Chilkat objects should be thread-safe. If you suspect this is the problem, then you can verify it by adding your own thread-safety synchronization mechanisms (such as critical sections / mutexes) to ensure that only one thread at a time is calling into a specific object instance. If the problem disappears after you've added external thread-safety mechanisms, then it's likely that Chilkat wasn't actually thread-safe.

2) A pointer is used such that the resource is either deleted or moved in one thread, but the other thread still uses the stale pointer.


answered Mar 21 '13 at 09:14

chilkat's gravatar image

chilkat ♦♦

Thanks for support, I have resolved issue.

(Mar 21 '13 at 11:15) Mehul

How did you resolve it? It might help others in the future.

(Mar 21 '13 at 12:52) jpbro ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Mar 18 '13 at 05:22

Seen: 2,296 times

Last updated: Mar 21 '13 at 12:52

powered by OSQA