k_kalyan
asked on
VC++ 6.0 : pthread_join is hanging (Linux to Windows porting)
Hello,
OS : Windows XP
Compiler : VC++ 6.0
pthreads library : http://sources.redhat.com/pthreads-win32/
In the following sample program, pthread_join is hanging in Windows and same is working in Linux.
Could u please explain why pthread_join is hanging here though the cancellation point is enabled.
What are all the possible causes for pthread_join to hang ?
========================== ========== ========== ========== ====
// Thread Creation -- finish the job -- and Join thread to the main thread
-------------------------- ---------- ---------- ---------- ---------- ---------- ----------
Sdf_fn_createThread (&(this->dnsProcessResults ThreadId), Sdf_co_null, dnsResultProcessorThread,\
(void*)this, &error));
pthread_cancel(this->dnsPr ocessResul tsThreadId );
pthread_join(this->dnsProc essResults ThreadId, &pExitCode); // Hanging ?
-------------------------- ---------- ---------- ---------- ---------- ---------- ----------
void* dnsResultProcessorThread ( void *pData) // Actual Job of the thread
{
fdset read_fds, write_fds;
int nfds,count;
timeVal *tvp,tv;
/* Cancel enable the thread */
pthread_setcancelstate(Sdf _mc_cancel Enable, Sdf_co_null);
while (1)
{
/* Check if the thread is cancelled */
pthread_testcancel();
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
/* wait for arrival of data , or a timeout to occur*/
count = select(nfds, &read_fds, &write_fds, NULL, tvp);
pthread_testcancel();
if (count < 0 && errno != EINVAL)
{
// Error Handling
continue;
}
if(FD_ISSET(pLookupDns->so ckfd, &read_fds) != 0)
{
/* Indicates that a new query is made.*/
FD_CLR(pLookupDns->sockfd, &read_fds);
char buf[9];
count = recv(pLookupDns->sockfd,bu f,9,0);
}
}
return NULL;
}
OS : Windows XP
Compiler : VC++ 6.0
pthreads library : http://sources.redhat.com/pthreads-win32/
In the following sample program, pthread_join is hanging in Windows and same is working in Linux.
Could u please explain why pthread_join is hanging here though the cancellation point is enabled.
What are all the possible causes for pthread_join to hang ?
==========================
// Thread Creation -- finish the job -- and Join thread to the main thread
--------------------------
Sdf_fn_createThread (&(this->dnsProcessResults
(void*)this, &error));
pthread_cancel(this->dnsPr
pthread_join(this->dnsProc
--------------------------
void* dnsResultProcessorThread ( void *pData) // Actual Job of the thread
{
fdset read_fds, write_fds;
int nfds,count;
timeVal *tvp,tv;
/* Cancel enable the thread */
pthread_setcancelstate(Sdf
while (1)
{
/* Check if the thread is cancelled */
pthread_testcancel();
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
/* wait for arrival of data , or a timeout to occur*/
count = select(nfds, &read_fds, &write_fds, NULL, tvp);
pthread_testcancel();
if (count < 0 && errno != EINVAL)
{
// Error Handling
continue;
}
if(FD_ISSET(pLookupDns->so
{
/* Indicates that a new query is made.*/
FD_CLR(pLookupDns->sockfd,
char buf[9];
count = recv(pLookupDns->sockfd,bu
}
}
return NULL;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.