Create Thread in ObjectARX

Create Thread in ObjectARX

Anonymous
Not applicable
1,010 Views
6 Replies
Message 1 of 7

Create Thread in ObjectARX

Anonymous
Not applicable
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
0 Likes
1,011 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
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
0 Likes
Message 3 of 7

Anonymous
Not applicable
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
0 Likes
Message 4 of 7

OysteinW
Advocate
Advocate
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
Not applicable
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
0 Likes
Message 6 of 7

Anonymous
Not applicable
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
0 Likes
Message 7 of 7

Anonymous
Not applicable
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
0 Likes