🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #27

Re: Multi-threading...

#27
From: Remy Lebeau (TeamB)
Date: Mon, 21 Jul 2008 06:22
45 lines
2071 bytes
"Carl Danley" <cdanley@codebyter.com> wrote in message 
news:4882cf55$1@newsgroups.borland.com...

> HANDLE ThreadA, ThreadB;

> ShowMessage("test2");

ShowMessage() is not thread-safe.  Do not use it outside of the main thread.

> //terminate Thread
> TerminateThread(Thread, false);

Use ExitThread() instead.  Or just exit from the function normally.  The OS 
will call ExitThread() for you.

> //initialize the thread
> DWORD Id;
> Thread = CreateThread(0, 0, ThreadA, Form1->Handle, CREATE_SUSPENDED, 
> &Id);

You are calling CreateThread() wrong.  It should look more like this:

    ThreadA = CreateThread(NULL, 0, &Thread1, NULL, CREATE_SUSPENDED, &Id);

> ResumeThread(Thread);

If you are going to call ResumeThread() right away, then there is no point 
in specifying the CREATE_SUSPENDED flag.

> When I actually add the full implementation into these threads, they crash 
> the program on exit.

Please show the actual implementation.

> What am I doing wrong?

You haven't shown enough code to diagnose that.

> The compiler error I get is Error 1400: Invalid Window Handle...

At which point in your code?  What does it look like?


Gambit 
Technical Details
Message-ID: <48842abd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!feeder.news-service.com!news.isoc.lu!newsgroups.borland.com!not-for-mail
References: <4882cf55$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b069f0aa9205a142
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4882cf55$1@newsgroups.borland.com>
Subject: Re: Multi-threading...
Date: Sun, 20 Jul 2008 23:22:06 -0700
Lines: 47
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 76.93.113.211
Message-ID: <48842abd$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1216621245 76.93.113.211 (20 Jul 2008 23:20:45 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!feeder.news-service.com!news.isoc.lu!newsgroups.borland.com!not-for-mail