Subj : Re: simple: passing a pointer to a handle to another thread To : comp.programming.threads From : Ben Hutchings Date : Thu Sep 29 2005 04:24 pm Ulrich Eckhardt wrote: > LeftHorn wrote: >> i have a main() function where i creates a class. > > No, you don't, you create an instance of a class, an object. > >> then i have a thread, where when initiated i pass the pointer (in the >> params) to this class (among other things). >> >> Inside this thread i i then access this object through a pointer, an >> one of the functions is a function that returns a handle to a Semaphore. >> >> But when doing that - i get an error "access overrun" attempt to access >> local block - when i have the class generated inside the thread, there >> is no problem. > > Could you please post the whole error-message and when exactly it happens? > Other than that, look at the pointer you want to pass into the thread > function and the pointer that arrives there, are they equal? > >> How can i share a handle that isnt global among threads ? > > If something is intended to be thread-local, you probably shouldn't. I know > that the MFC make some use of thread-local storage and because of that you > can't use CWnd objects across threads. MFC keeps a cache in each thread of temporary CWnd wrappers for foreign window handles, and flushes it at the bottom of the message loop. Explicitly created CWnd objects can be passed between threads, though each window "belongs to" a single thread. Ben. -- Ben Hutchings Beware of bugs in the above code; I have only proved it correct, not tried it. - Donald Knuth .