[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
| Title: | C++ | 
| Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) | 
| Moderator: | DECCXX::AMARTIN | 
|  | 
| Created: | Fri Nov 06 1987 | 
| Last Modified: | Thu Jun 05 1997 | 
| Last Successful Update: | Fri Jun 06 1997 | 
| Number of topics: | 3604 | 
| Total number of notes: | 18242 | 
3414.0. "Need help pthread ." by HGOVC::SIUKEUNGLEE () Tue Jan 28 1997 10:50
    
       <<< TURRIS::DISK$NOTES_PACK2:[NOTES$LIBRARY]DIGITAL_UNIX.NOTE;1 >>>
                -< DIGITAL UNIX (FORMERLY KNOWN AS DEC OSF/1) >-
================================================================================
Note 8607.0                Need on on pthread library.                No replies
HGOVC::SIUKEUNGLEE                                  162 lines  28-JAN-1997 01:41
--------------------------------------------------------------------------------
Hi,
    
    Customer report some problem when there program link with pthread
    library. The program will crash and core file generated. Could someone
    help me to take a look of the problem  ?
    
    
    # ./test
    Data Address:0x14000d7c0
    Entry Address:0x140024440
    Entry Address:0x140024280
    Key"12345"found,Entry Address:0x140024440
            Data=hello
    Key"abcde"found,Entry Address:0x140024280
    CDummy data:999
    DECthreads Last Chance handler: thread 2 exiting on status exception
    0x177db005
    Exception: Invalid memory address (dce / thd)
    Resources lost(coredump)
    
    # decladebug ./test ./core
    Welcome to the Ladebug Debugger Version 4.0-25
    ------------------ 
    object file name: ./test 
    core file name: ./core
    Reading symbolic information ...done
    Core file produced from executable test
    Thread 0x2 terminated at PC 0x3ff8053eab0 by signal IOT
    (ladebug) t
    >0  0x3ff8053eab0 in nxm_thread_kill(0x3ffc0081e10, 0x3ffc0080338, 0x2,
    0x3ffc0080310, 0x2, 0x0) DebugInformationStrippedFromFile19:???
    #1  0x3ff8056f1dc in pthread_kill(0x3ffc0082590, 0x140018030,
    0x2130455, 0x3ff8055beb8, 0x0, 0x14002fe78)
    DebugInformationStrippedFromFile100:???
    #2  0x3ff80575b8c in UnknownProcedure10FromFile104(0x2130455,
    0x3ff8055beb8, 0x0, 0x14002fe78, 0x3ff8010fb24, 0x3ffc0080c50)
    DebugInformationStrippedFromFile104:???
    #3  0x3ff8010fb20 in /usr/shlib/libc.so
    #4  0x3ff80159f70 in raise(0x3ff8010fb24, 0x3ffc0080c50, 0x3ff80159f74,
    0x3ff80575ab8, 0x3ff80170aac, 0x0)
    DebugInformationStrippedFromFile441:???
    #5  0x3ff80170aa8 in abort(0x14002f438, 0x0, 0x0, 0x0,
    0xffffffff00000000, 0x177db005) DebugInformationStrippedFromFile329:???
    #6  0x3ff80565c74 in errAbort(0x0, 0x0, 0xffffffff00000000, 0x177db005,
    0x3ff8056650c, 0x3ffc00802a0) DebugInformationStrippedFromFile90:???
    #7  0x3ff80566508 in UnknownProcedure2FromFile91(0x14002f6f8,
    0x3ff805669d4, 0x14002f9d8, 0x3ff8055beb8, 0x14002fa80, 0x3ff807b3488)
    DebugInformationStrippedFromFile91:???
    #8  0x3ff807b220c in UnknownProcedure4FromFile1(0x3ff807b3624, 0x0,
    0x14002f6f8, 0x3ff80574930, 0x14002fa48, 0x3ff805669d4)
    DebugInformationStrippedFromFile1:???
    #9  0x3ff807b3620 in UnknownProcedure16FromFile1(0x0, 0x14002fe78,
    0x14002fe78, 0x14002ef18, 0xabadabad00beed00, 0x0)
    DebugInformationStrippedFromFile1:???
    #10 0x3ff807b3664 in exc_unwind(0x14002fe78, 0x14002ef18,
    0xabadabad00beed00, 0x0, 0x3ff807b254c, 0x35)
    DebugInformationStrippedFromFile1:???
    #11 0x3ff807b2548 in exc_raise_exception(0x120001a50, 0x0, 0x14002f9d8,
    0x0, 0x120002138, 0x120002214) DebugInformationStrippedFromFile1:???
    #12 0x3ff805669d4 in pthread_exc_raise_np(0x0, 0x0, 0x3ff80574718,
    0x120002214, 0x0, 0x0) DebugInformationStrippedFromFile91:???
    #13 0x3ff80574930 in thdBase(0x0, 0x0, 0x0, 0x0, 0x45586732, 0x3)
    DebugInformationStrippedFromFile102:???
    
    
    
    The test program are attached follow.
    
    Welcome any suggestion !
    
    David Lee.
    
    [ Cross posted to Digital UNIX note conference ]
        
    =========================================================================
    
    Digital UNIX 4.0b with all latest patches installed.
    DCE for UNIX 2.0a
    
    
#include <cxx/iostream.hxx>
#include <search.h>
#include <stdlib.h>
#include <pthread.h>
class CDummy
{
public:
	CDummy(int val){data = val;}
	print() { cout<< "CDummy data:"<<dec<<data<<endl;}
private:
	int data;
};
void InsertTab(char*key,void*data)
{
	ENTRY cell;
	cell.key = new char[10];
	strcpy(cell.key,key);
	cell.data=(char*)data;
	ENTRY*item;
	if((item = hsearch(cell,ENTER))==NULL){
		cout <<"Hash table full";
		exit;
	}
else
	cout<<"Entry Address:"<<hex<<item<<endl;
}
void* SearchTab(char* key)
{
	ENTRY* item;
	ENTRY s={key};
	if((item = hsearch(s,FIND))==NULL)
		cout<<"Entry not Found!!"<<endl; 
	else
		cout<<"Key\""<<key<<"\"found,Entry Address:"<<hex<<item<<endl;
		return item->data;
}
void* sos(void* param)
{
	char* a=(char*)SearchTab("12345");
	cout<<"\tData="<<a<<endl;
	((CDummy*)SearchTab("abcde"))->print();
	return NULL;
}
void main(void)
{
	if(hcreate(100)==0)
	cout<<"error creating hash table";
	char* data = new char[10];
	cout<<"Data Address:"<<hex<<(ulong*)data<<endl;
	strcpy(data,"hello");
	CDummy *theDummy = new CDummy(999);
	InsertTab("12345",data);
	InsertTab("abcde",theDummy);
	char* a=(char*)SearchTab("12345");
	cout<<"\tData="<<a<<endl;
	((CDummy*)SearchTab("abcde"))->print();
	
	pthread_t m_thread;
	pthread_create(&m_thread,
		       NULL,
			sos,
		       NULL);
	pthread_join(m_thread,NULL);
}
| T.R | Title | User | Personal Name
 | Date | Lines | 
|---|
| 3414.1 | Try the threads notesfile: CLT::CMA | WIDTH::MDAVIS | Mark Davis - compiler maniac | Tue Jan 28 1997 11:30 | 15 | 
|  | 1. try running under the debugger so the debugger can catch the
memory problem, then do a backtrace.  The backtrace you give is
after the threads library has caught the segfault, looked around
to see what to do, and then called pthread_kill.
2. since you don't give the compile or link command, no one can
try helping.
3. most people don't have dce, either.
4. and it doesn't look like a compiler problem, so we don't have spare
cycles to spend debugging your customer's problem.
5. xref to c_plus_plus # 3352 for a previous, non-threaded version
that failed due to dce problems.....
 | 
| 3414.2 | possible problem iin the hash table library routines... | DECC::J_WARD |  | Tue Jan 28 1997 13:49 | 12 | 
|  | 
I don't think the hash table functions you are using
are thread-safe. I see on the man page that Digital
used to have reentrant versions (hcreate_r(), hsearch_r(),
etc.) but that they are currently only supported for backward
compatibility.
When talking about the non-reentrant functions it says:
"  If several threads want to use the same hash table, they must perform their
  own synchronization. "
 |