<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Programm hängt sich bei Variablenzugriff auf]]></title><description><![CDATA[<p>Hallo !<br />
Ich bin gerade dabei eine DLL (Plugin) für Weaverslave zu schreiben.<br />
Dummerweise hängt sich mein Code beim Zugriff auf eine Variable auf...<br />
Es gibt keine Fehlermeldung. Die Codeausführung bleibt einfach stehen und das Programm (Weaverslave) verbraucht nahezu 100% Prozessorleistung (endlosschleife oder so). (Muss am Weaverslavecode liegen)</p>
<p>Es handelt sich bei der Variable um</p>
<pre><code class="language-cpp">char dateiName[MAX_PATH];
</code></pre>
<p>.<br />
Sie ist Bestandteil der Klasse Defiant_Node(=BaumstrukturKnoten) (in Start cl_Tree) die von einem Thread rekursiv gefüllt wird.<br />
Das ganze läuft folgendermaßen:<br />
Defiantklasse beinhaltet</p>
<pre><code class="language-cpp">Defiant_Node* cl_Tree;
</code></pre>
<p>.<br />
Ruft in Defiant::Start einen Thread auf und übergibt cl_Tree.<br />
Anschließend wird die Nachrichtenschleife eines Fensters gestartet.</p>
<p>Der Thread füllt cl_Tree.<br />
Schließt das Fenster / Beendet die Nachrichtenschleife.<br />
Beendet sich selbst.</p>
<p>Defiant::Start verwendet den gefüllten Baum cl_Tree weiter.<br />
Hängt sich auf.</p>
<p>Woran liegt es, dass sich ein Programm beim Zugriff auf eine Variable aufhängt?<br />
Muss ich beim Benutzen von Threads noch weiteres beachten, obwohl hier keine Überlagerungen auftreten (sollten)?</p>
<pre><code class="language-cpp">unsigned __stdcall def_WorkingThread(void* pParam)
{
	Defiant_Thread_Parameter* param;
	param = (Defiant_Thread_Parameter*) pParam;

	Defiant::wt_GatherFiles(param-&gt;df_locs,param-&gt;Pfad,param-&gt;Name);

	char* targetFile = new char[MAX_PATH];
	targetFile = strcat(strdup(param-&gt;Pfad),
		strdup(param-&gt;Name));
	MessageBox(NULL,targetFile,&quot;TargetFile start&quot;,0);

	param-&gt;df_node = new Defiant_Node(targetFile,param-&gt;Name,param-&gt;df_locs);
	// abhängigen-Strang gefüllt

	SendMessage(param-&gt;hWnd,WM_CLOSE,NULL,NULL);
	// progress-Fenster schließen

	// weiteres siehe Defiant::Start
	return 0;
}
// [...]
void Defiant::Start(char* FilePos,int len,HINSTANCE hInstance)
{

	ProjektPath = new char[len];
	ProjektName = new char[len];
	strcpy(ProjektName,FilePos);
	ProjektName = GetFileName(FilePos,len);
	ProjektPath = GetFilePath(FilePos,len);
		// ProjektPath beinhaltet nun den Pfad (mit \ hinten)

	// parameter &quot;speichern&quot;
	//cl_Locations.Add(ProjektPath,ProjektName);

	// Fensteroberfläche laden...
	Progress_Window pro_Fenster;
	pro_Fenster.Show_Pro_Window(hInstance);

	// WorkerThread starten...
	int thread_id=0;
	unsigned ti1;
	thread_parameter.Pfad = ProjektPath;
	thread_parameter.Name = ProjektName;
	thread_parameter.hWnd = pro_Fenster.hWnd;
	thread_parameter.df_locs = &amp;cl_Locations;
	thread_parameter.df_node = cl_Tree;

	Defiant::SetStatus(pro_Fenster.hWnd,0,pro_Init,NULL);

	_beginthreadex(0,
		0,
		def_WorkingThread,
		(void*)&amp;thread_parameter,
		0,
		&amp;ti1 
		);

	// MessageLoop betreten...
	pro_Fenster.Enter_Message_Loop(hInstance);

	// Fenster geschlossen (durch den thread)
	// Schleife beendet

	// resultfenster+hwnds vorbereiten
	Result_Window res_Fenster;
	res_Fenster.Show_Res_Window(hInstance);
	// hwnds gefüllt

	HWND Tview;
	Tview = res_Fenster.hTree;
	MessageBox(NULL,&quot;&lt;&lt;&lt;&lt;&lt;test&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;,&quot;&quot;,0);
// nach dem klick auf ok hängt sich das programm auf
	cl_Tree-&gt;FillTV(Tview,NULL);
	MessageBox(NULL,&quot;filling ended&quot;,&quot;&quot;,0);
	res_Fenster.Enter_Message_Loop(hInstance);
}
// [...]
Defiant_Node::FillTV(HWND Tview,HTREEITEM base)
{
	MessageBox(NULL,dateiName,&quot;&quot;,0);
}
// [...]
class Defiant_Node  
{
public:
	FillTV(HWND,HTREEITEM);
	Defiant_Node(char*,char*,Defiant_Locations*);
	Defiant_Node();
	static HTREEITEM AddItemToTree(HWND, LPSTR, HTREEITEM, HTREEITEM);
	virtual ~Defiant_Node();

	char dateiName[MAX_PATH];
	deque&lt;Defiant_Node*&gt; links;
private:
	int links_count;
	HTREEITEM tv_Item;
	Parse(Defiant_Locations*);
	char dateiLocation[MAX_PATH];
	char* tmp_Buffer;
	DWORD datei_size;
	HANDLE datei;
};
Defiant_Node::Defiant_Node(char *TargetFile,char* TargetFileName,Defiant_Locations* locs)
{
	links_count = 0;

	//targetfile = gesamter dateipfad+name
	//targetfilename = nur name
	char statBuffer[MAX_PATH+sizeof(pro_Read_)];
	strcpy(dateiLocation,TargetFile);
	strcpy(dateiName,TargetFileName);
	// lokale kopie muss angefertigt werden !

	datei = CreateFile(
		dateiLocation,          // pointer to name of the file
		GENERIC_READ,       // access (read-write) mode
		FILE_SHARE_READ,           // share mode
		NULL,// pointer to security attributes
		OPEN_EXISTING,  // how to create
		NULL,  // file attributes
		NULL         // handle to file with attributes to 
										// copy
		);
	datei_size = GetFileSize(datei,NULL);
	strcpy(statBuffer,pro_Read_);
	strcat(statBuffer,dateiLocation);
	Defiant::SetStatus(NULL,0,statBuffer,datei_size);
		// status : Reading blblblabalba

	tmp_Buffer = new char[datei_size];
	if(tmp_Buffer == NULL)
		MessageBox(NULL,pro_Read_Mem_Error,gen_Error,MB_OK | MB_ICONERROR);

	ULONG read=0;
	ReadFile(
		datei,          // handle of file to read
		tmp_Buffer,     // pointer to buffer that receives data
		datei_size,		// number of bytes to read
		&amp;read,			// pointer to number of bytes read
		NULL			// pointer to structure for data
		);
		// tmp_Buffer ist mit der Datei gefüllt...

	//Parsen wenn erfolgreich
	if(tmp_Buffer != NULL)
		Parse(locs);
	else
		Defiant::SetStatus(NULL,0,pro_Read_noread,NULL);
}
Defiant_Node::Parse(Defiant_Locations* locs)
{

	tmp_Buffer = strupr(tmp_Buffer);
	// uppercase

	Defiant::SetStatus(NULL,0,NULL,locs-&gt;GetSize());
	for(int i=0;i&lt;locs-&gt;GetSize();i++)
	{
		//MessageBox(NULL,&quot;parsing&quot;,locs-&gt;GetItem(i)-&gt;loc_Filename,0);
		if(strstr(tmp_Buffer,locs-&gt;GetItem(i)-&gt;loc_Filename)!=NULL)
		{
			// dateiname wurde gefunden

			// pfad\datei vorbereiten
			char* pfad_Datei = new char[MAX_PATH];
			pfad_Datei = strcat(locs-&gt;GetItem(i)-&gt;loc_Path,
				locs-&gt;GetItem(i)-&gt;loc_Filename);

			if(strcmp(pfad_Datei,
				dateiLocation) != 0){
				// dateinamen (!) miteinander vergleichen
				char* buf;
				Defiant_Locations* pointer;
				buf = strdup(locs-&gt;GetItem(i)-&gt;loc_Filename);
				pointer = locs-&gt;Delete(i);
				if(pointer != NULL)
					locs = pointer;
				//MessageBox(NULL,locs-&gt;GetItem(2)-&gt;loc_Filename,locs-&gt;GetItem(3)-&gt;loc_Filename,0);
				links.push_back(
					new Defiant_Node(pfad_Datei,
					buf,
					locs)
					);
				links_count++;

				// sich nicht selbst aufrufen
				// TODO: das alte &quot;eigene&quot; locationding löschen spätestens
				// jetzt löschen (vor new natürlich)
			}
			delete pfad_Datei;
		}
		Defiant::SetStatus(NULL,i,NULL,NULL);
	}

}
</code></pre>
<p>Viel Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> aber vielen Dank an jeden, der sich gedanklich mit meinem Problem beschäftigt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/96360/programm-hängt-sich-bei-variablenzugriff-auf</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 22:37:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/96360.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 31 Dec 2004 15:33:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Programm hängt sich bei Variablenzugriff auf on Fri, 31 Dec 2004 15:33:36 GMT]]></title><description><![CDATA[<p>Hallo !<br />
Ich bin gerade dabei eine DLL (Plugin) für Weaverslave zu schreiben.<br />
Dummerweise hängt sich mein Code beim Zugriff auf eine Variable auf...<br />
Es gibt keine Fehlermeldung. Die Codeausführung bleibt einfach stehen und das Programm (Weaverslave) verbraucht nahezu 100% Prozessorleistung (endlosschleife oder so). (Muss am Weaverslavecode liegen)</p>
<p>Es handelt sich bei der Variable um</p>
<pre><code class="language-cpp">char dateiName[MAX_PATH];
</code></pre>
<p>.<br />
Sie ist Bestandteil der Klasse Defiant_Node(=BaumstrukturKnoten) (in Start cl_Tree) die von einem Thread rekursiv gefüllt wird.<br />
Das ganze läuft folgendermaßen:<br />
Defiantklasse beinhaltet</p>
<pre><code class="language-cpp">Defiant_Node* cl_Tree;
</code></pre>
<p>.<br />
Ruft in Defiant::Start einen Thread auf und übergibt cl_Tree.<br />
Anschließend wird die Nachrichtenschleife eines Fensters gestartet.</p>
<p>Der Thread füllt cl_Tree.<br />
Schließt das Fenster / Beendet die Nachrichtenschleife.<br />
Beendet sich selbst.</p>
<p>Defiant::Start verwendet den gefüllten Baum cl_Tree weiter.<br />
Hängt sich auf.</p>
<p>Woran liegt es, dass sich ein Programm beim Zugriff auf eine Variable aufhängt?<br />
Muss ich beim Benutzen von Threads noch weiteres beachten, obwohl hier keine Überlagerungen auftreten (sollten)?</p>
<pre><code class="language-cpp">unsigned __stdcall def_WorkingThread(void* pParam)
{
	Defiant_Thread_Parameter* param;
	param = (Defiant_Thread_Parameter*) pParam;

	Defiant::wt_GatherFiles(param-&gt;df_locs,param-&gt;Pfad,param-&gt;Name);

	char* targetFile = new char[MAX_PATH];
	targetFile = strcat(strdup(param-&gt;Pfad),
		strdup(param-&gt;Name));
	MessageBox(NULL,targetFile,&quot;TargetFile start&quot;,0);

	param-&gt;df_node = new Defiant_Node(targetFile,param-&gt;Name,param-&gt;df_locs);
	// abhängigen-Strang gefüllt

	SendMessage(param-&gt;hWnd,WM_CLOSE,NULL,NULL);
	// progress-Fenster schließen

	// weiteres siehe Defiant::Start
	return 0;
}
// [...]
void Defiant::Start(char* FilePos,int len,HINSTANCE hInstance)
{

	ProjektPath = new char[len];
	ProjektName = new char[len];
	strcpy(ProjektName,FilePos);
	ProjektName = GetFileName(FilePos,len);
	ProjektPath = GetFilePath(FilePos,len);
		// ProjektPath beinhaltet nun den Pfad (mit \ hinten)

	// parameter &quot;speichern&quot;
	//cl_Locations.Add(ProjektPath,ProjektName);

	// Fensteroberfläche laden...
	Progress_Window pro_Fenster;
	pro_Fenster.Show_Pro_Window(hInstance);

	// WorkerThread starten...
	int thread_id=0;
	unsigned ti1;
	thread_parameter.Pfad = ProjektPath;
	thread_parameter.Name = ProjektName;
	thread_parameter.hWnd = pro_Fenster.hWnd;
	thread_parameter.df_locs = &amp;cl_Locations;
	thread_parameter.df_node = cl_Tree;

	Defiant::SetStatus(pro_Fenster.hWnd,0,pro_Init,NULL);

	_beginthreadex(0,
		0,
		def_WorkingThread,
		(void*)&amp;thread_parameter,
		0,
		&amp;ti1 
		);

	// MessageLoop betreten...
	pro_Fenster.Enter_Message_Loop(hInstance);

	// Fenster geschlossen (durch den thread)
	// Schleife beendet

	// resultfenster+hwnds vorbereiten
	Result_Window res_Fenster;
	res_Fenster.Show_Res_Window(hInstance);
	// hwnds gefüllt

	HWND Tview;
	Tview = res_Fenster.hTree;
	MessageBox(NULL,&quot;&lt;&lt;&lt;&lt;&lt;test&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;,&quot;&quot;,0);
// nach dem klick auf ok hängt sich das programm auf
	cl_Tree-&gt;FillTV(Tview,NULL);
	MessageBox(NULL,&quot;filling ended&quot;,&quot;&quot;,0);
	res_Fenster.Enter_Message_Loop(hInstance);
}
// [...]
Defiant_Node::FillTV(HWND Tview,HTREEITEM base)
{
	MessageBox(NULL,dateiName,&quot;&quot;,0);
}
// [...]
class Defiant_Node  
{
public:
	FillTV(HWND,HTREEITEM);
	Defiant_Node(char*,char*,Defiant_Locations*);
	Defiant_Node();
	static HTREEITEM AddItemToTree(HWND, LPSTR, HTREEITEM, HTREEITEM);
	virtual ~Defiant_Node();

	char dateiName[MAX_PATH];
	deque&lt;Defiant_Node*&gt; links;
private:
	int links_count;
	HTREEITEM tv_Item;
	Parse(Defiant_Locations*);
	char dateiLocation[MAX_PATH];
	char* tmp_Buffer;
	DWORD datei_size;
	HANDLE datei;
};
Defiant_Node::Defiant_Node(char *TargetFile,char* TargetFileName,Defiant_Locations* locs)
{
	links_count = 0;

	//targetfile = gesamter dateipfad+name
	//targetfilename = nur name
	char statBuffer[MAX_PATH+sizeof(pro_Read_)];
	strcpy(dateiLocation,TargetFile);
	strcpy(dateiName,TargetFileName);
	// lokale kopie muss angefertigt werden !

	datei = CreateFile(
		dateiLocation,          // pointer to name of the file
		GENERIC_READ,       // access (read-write) mode
		FILE_SHARE_READ,           // share mode
		NULL,// pointer to security attributes
		OPEN_EXISTING,  // how to create
		NULL,  // file attributes
		NULL         // handle to file with attributes to 
										// copy
		);
	datei_size = GetFileSize(datei,NULL);
	strcpy(statBuffer,pro_Read_);
	strcat(statBuffer,dateiLocation);
	Defiant::SetStatus(NULL,0,statBuffer,datei_size);
		// status : Reading blblblabalba

	tmp_Buffer = new char[datei_size];
	if(tmp_Buffer == NULL)
		MessageBox(NULL,pro_Read_Mem_Error,gen_Error,MB_OK | MB_ICONERROR);

	ULONG read=0;
	ReadFile(
		datei,          // handle of file to read
		tmp_Buffer,     // pointer to buffer that receives data
		datei_size,		// number of bytes to read
		&amp;read,			// pointer to number of bytes read
		NULL			// pointer to structure for data
		);
		// tmp_Buffer ist mit der Datei gefüllt...

	//Parsen wenn erfolgreich
	if(tmp_Buffer != NULL)
		Parse(locs);
	else
		Defiant::SetStatus(NULL,0,pro_Read_noread,NULL);
}
Defiant_Node::Parse(Defiant_Locations* locs)
{

	tmp_Buffer = strupr(tmp_Buffer);
	// uppercase

	Defiant::SetStatus(NULL,0,NULL,locs-&gt;GetSize());
	for(int i=0;i&lt;locs-&gt;GetSize();i++)
	{
		//MessageBox(NULL,&quot;parsing&quot;,locs-&gt;GetItem(i)-&gt;loc_Filename,0);
		if(strstr(tmp_Buffer,locs-&gt;GetItem(i)-&gt;loc_Filename)!=NULL)
		{
			// dateiname wurde gefunden

			// pfad\datei vorbereiten
			char* pfad_Datei = new char[MAX_PATH];
			pfad_Datei = strcat(locs-&gt;GetItem(i)-&gt;loc_Path,
				locs-&gt;GetItem(i)-&gt;loc_Filename);

			if(strcmp(pfad_Datei,
				dateiLocation) != 0){
				// dateinamen (!) miteinander vergleichen
				char* buf;
				Defiant_Locations* pointer;
				buf = strdup(locs-&gt;GetItem(i)-&gt;loc_Filename);
				pointer = locs-&gt;Delete(i);
				if(pointer != NULL)
					locs = pointer;
				//MessageBox(NULL,locs-&gt;GetItem(2)-&gt;loc_Filename,locs-&gt;GetItem(3)-&gt;loc_Filename,0);
				links.push_back(
					new Defiant_Node(pfad_Datei,
					buf,
					locs)
					);
				links_count++;

				// sich nicht selbst aufrufen
				// TODO: das alte &quot;eigene&quot; locationding löschen spätestens
				// jetzt löschen (vor new natürlich)
			}
			delete pfad_Datei;
		}
		Defiant::SetStatus(NULL,i,NULL,NULL);
	}

}
</code></pre>
<p>Viel Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> aber vielen Dank an jeden, der sich gedanklich mit meinem Problem beschäftigt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/683896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/683896</guid><dc:creator><![CDATA[Trigger_Hurt]]></dc:creator><pubDate>Fri, 31 Dec 2004 15:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Programm hängt sich bei Variablenzugriff auf on Sat, 01 Jan 2005 15:59:08 GMT]]></title><description><![CDATA[<p>ja hehehe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">cl_Tree = thread_parameter.df_node;
</code></pre>
<p>Eine Zeile<br />
Enorm viel Wirkung...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/684223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/684223</guid><dc:creator><![CDATA[Trigger_Hurt]]></dc:creator><pubDate>Sat, 01 Jan 2005 15:59:08 GMT</pubDate></item></channel></rss>