Archived Forum Post

Index of archived forum posts


Passing CkEmail* to Another thread Not working

Mar 21 '13 at 12:52

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)


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.


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.