ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Thread in ObjectARX

6 REPLIES 6
Reply
Message 1 of 7
zhengy
672 Views, 6 Replies

Create Thread in ObjectARX

Dear all,

I am trying to create a thread in an ObjectARX project. The function I used is
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, NULL, 0, &dwThreadId).

After the creation, the thread ID and Handle are returned successfully. But the created thread has never run.

Can anyone tell me if there is any way to solve this problem?

Cheers,

Yang
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: zhengy

Yang:

> After the creation, the thread ID and Handle are returned successfully.
> But the created thread has never run.

How are you determining that the thread hasn't executed? Are you trying
to create the thread from within your DllMain() function?
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 3 of 7
zhengy
in reply to: zhengy

Hi Owen,

Thanks for your kindly reply. I attached the snippet of my
code. I have registered a command "watch" in the command stack to activate the watchDb() method.

After the CreateThread () method, I got a returned value for the thread ID and the handle.

However, nothing is printed out like the first operation (print the sentence ("Already in Thread")), which makes me believe that the thread is not run.

I also use a software (like Windows Task Manager) that is able to trace all the Processes and their Threads, but the ThreadFun thread is not in the list.

void watchDb ()
{
if (gpDbr == NULL) {
gpDbr = new AsdkDbReactor();
}

acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr);

DWORD dwThreadId=0;
if (CreateThread(NULL,
0, (LPTHREAD_START_ROUTINE)ThreadFunc, NULL,
0, &dwThreadId) == NULL)
{
acutPrintf("NULL Thread\n");
return ;
}
acutPrintf("\nThread id = %d\n", dwThreadId);
}


void ThreadFunc () {
acutPrintf("Already in Thread\n");
...
}


Thanks a lot.

Yang
Message 4 of 7
OysteinW
in reply to: zhengy

From objectARX doc:

"ObjectARX Does Not Support Multi-Threaded Programming
If you spawn multiple threads in your application, make sure that no more than one of the threads at a time invokes anything in the ObjectARX system."
Message 5 of 7
Anonymous
in reply to: zhengy

From the MSDN docs for CreateThread(): "A thread in an executable that calls
the C run-time library (CRT) should use the _beginthread and _endthread
functions for thread management...".

Dan

wrote in message news:5250034@discussion.autodesk.com...
Hi Owen,

Thanks for your kindly reply. I attached the snippet of my
code. I have registered a command "watch" in the command stack to activate
the watchDb() method.

After the CreateThread () method, I got a returned value for the thread ID
and the handle.

However, nothing is printed out like the first operation (print the sentence
("Already in Thread")), which makes me believe that the thread is not run.

I also use a software (like Windows Task Manager) that is able to trace all
the Processes and their Threads, but the ThreadFun thread is not in the
list.

void watchDb ()
{
if (gpDbr == NULL) {
gpDbr = new AsdkDbReactor();
}

acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr);

DWORD dwThreadId=0;
if (CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)ThreadFunc, NULL,
0, &dwThreadId) == NULL)
{
acutPrintf("NULL Thread\n");
return ;
}
acutPrintf("\nThread id = %d\n", dwThreadId);
}


void ThreadFunc () {
acutPrintf("Already in Thread\n");
...
}


Thanks a lot.

Yang
Message 6 of 7
Anonymous
in reply to: zhengy

Your acutPrintf() call is not a reliable way to check whether the thread
is executing, because ObjectARX API functions do not support asynchronous
reentrancy. Use something independent of AutoCAD (such OutputDebugString
under a debugger) to test whether your thread is executing. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 7 of 7
zhengy
in reply to: zhengy

Yes, Owen, you are definitely right. I tried other approaches and found out that the created thread was running, but it could not print out anything on the AutoCAD screen using acutPrintf().

Thanks for all the replies to help me out.

Cheers,

Yang Message was edited by: zhengy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost