BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Thread::WaitFor() issue
Goto page 1, 2, 3 ... 30, 31, 32  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
server
Guest





PostPosted: Fri Feb 17, 2006 9:03 am    Post subject: Thread::WaitFor() issue Reply with quote



message unavailable
Back to top
Kiwi
Guest





PostPosted: Fri Feb 17, 2006 9:03 am    Post subject: Re: Thread::WaitFor() issue Reply with quote



Hi Remy,

I think I tried a form of your example below and found that with the code in
the main form
thread->Terminate(); // This didn't allow the thread to get to
the Execute() function
thread->WaitFor();

and if I changed the order to
thread->WaitFor(); // Then the main program waited here for
the thread to finish
thread->Terminate(); // so using the thread is a waste of time.

What am I missing?

I have a main program and several threads, say, threadA, threadB, and
threadC. The main program calls the threads and what I want is for threadB
to wait for threadA to finish (if threadA is running). How would you
recommend I use the thread->WaitFor() in this case.

Thanks,
Roger


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:43d7cc2a$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Leonid R" <waxhall (AT) yahoo (DOT) com> wrote in message
news:43d7977f$1 (AT) newsgroups (DOT) borland.com...

Whenever I'm trying to use Thread::WaitFor() function I'm
receiving "Thread Error: The handle is invalid (6)" exception
message box.

I am assuming that you are using BCB 6 or higher, is that right? BCB 6
introduced that bug into WaitFor() (see QC #6080 for details). The issue
only happens when you have the thread's FreeOnTerminate property set to
true, since the thread's handle gets destroyed while WaitFor() is still
waiting on it. The reason you get the exception is because Borland
changed
the way WaitFor() handles errors in BCB 6. Earlier versions did not throw
the exception, WaitFor() existed normally instead.

In short, do NOT use FreeOnTerminate with WaitFor(). FreeOnTerminate is
best used only when you want ot start the thread and forget about it, not
keeping track of it at all. But if you need to wait on the thread, then
you
should free the thread manually after the waiting is finished, ie:

void __fastcall TMainForm::Button1Click(TObject *Sender)
{
if( !thread )
thread = new TTestThread(false);
}

void __fastcall TMainForm::Button2Click(TObject *Sender)
{
if( thread )
{
thread->Terminate();
thread->WaitFor();
delete thread;
thread = NULL;
}
}


Gambit

Back to top
Ed Mulroy
Guest





PostPosted: Mon Mar 27, 2006 2:03 pm    Post subject: Re: Need help - Can't program today Reply with quote



Thanks for the comments.

Catch by reference: A great comment that solves possible problems. Same for
the remark about 'explicit'. Much thanks!!!

There is no need to overload []. It is not the function of the class to
wrap an array type. It is to hide the altered behavior of the current C++
new vs the way C++' new of 17 years ago worked so that an old program could
be handled with a current compiler. I only put the delete [] call into the
denstructor to make things easier so that I could erase them rather than
convert the "delete" calls to "delete []".

Yes, I know a new char[0] will not throw an exception and will provide a
unique address. As you can see from the comment in the code, in this case
it should fail.

The #include <string> is why it did not complain about the missing
definition of bad_alloc.

.. Ed

Quote:
From: Alisdair Meredith
alisdair.meredith@no-spam-splease (AT) uk (DOT) renaultf1.com
Subject: Re: Need help - Can't program today

Date: Sunday, March 26, 2006 10:52 PM

Ed Mulroy wrote:

Quote:
Comments invited.

#include <cstring> // for NULL

template <typename T> class MyNew
{
public:
MyNew(unsigned howmany = 1)
: tsize(howmany)
{
try
{
buf = (howmany) ? new T[howmany] : NULL;
}
catch (bad_alloc)
{
buf = NULL;
}
}

~MyNew() { delete [] buf; }

operator T* () { return buf; }
const MyNew & operator = (const MyNew &) const { return *this; }
unsigned AllocSize() const { return tsize; }

private:
T *buf;
unsigned tsize;
MyNew(const MyNew &); // unimplemented
};


This copy assignment operator is just asking for trouble.

MyNew< int > a( 5 );
MyNew< int > b( 10 );

a = b;

int * pa = a;
int * pb = b;

if( pa != pb )
{
std::cout << "I am SURE I assigned a = b" << endl;
}

That said, an assignment operator that is const?! That should have
been the real clue, in hindsight - this class does something strange.



It is unusual to have something assignable but not copyable anyway.
MyNew< int > a( 10 );
MyNew< int > b = a; // error on this line
b = a; // but no on this


I mild efficiency/correctness issue would be to catch std::bad_alloc by
(const) reference. In theory the new operator can throw an exception
derived from std::bad_alloc, and catch-by-value will miss it.

std::bad_alloc is declared in header <stdexcept> - so you have more
than std namespace problems if this compiles in your test harness.


I presume you know that new int[0] is well formed in C++ and will
return a unique pointer each time it is called? i.e. there is no need
for the workaround for the size 0 array, although you may choose to do
so for other reasons beyond the scope of this example.

It seems odd to wrap an array type, but not overload operator[].

You should probably make the constructor explicit, unless you want the
following code to compile:

MyNew< int > a = 10;
Back to top
hank
Guest





PostPosted: Thu Apr 27, 2006 8:03 am    Post subject: Re: Adding Languages to a Project(BDS2006) Reply with quote

Quote:
Hi all:

Borland Help say that:

You can add languages to your project by using the Satellite Assembly
Wizard
(.NET) or Resource DLL Wizard (Win32). For each language that you add, the
wizard generates a resource module project in your project group. Each
resource module project is given an extension based on the languageˇ¦s
locale. To add a language to a project
1.. Save and build your project.
2.. With your project open in the IDE, choose Project->Languages->Add.
The
wizard is displayed.

But I can't find the Project->Languages item , Why ?

Please help.



Back to top
Hans Galema
Guest





PostPosted: Fri Apr 28, 2006 9:03 am    Post subject: Re: Invalid value of struct tm's 'tm_isdst'-element (when tr Reply with quote

MR wrote:

Quote:
2nd April 2006, 2:59 (=> is_now_summertime==false)
2nd April 2006, 3:00 (=> is_now_summertime==true)

you meant: tm->tm_isdst.

<help for localtime>
localtime accepts the address of a value returned by time and returns
a pointer to the structure of type tm containing the time elements.
It corrects for the time zone and possible daylight saving time.

The global long variable _timezone contains the difference in seconds
between GMT and local standard time (in PST, _timezone is 8 x 60 x 60).
The global variable _daylight is used to tell the RTL's functions
(mktime & localtime) whether they should take daylight saving time
into account if it runs into a date that would normally fall into that
category. It is set to 1 if the daylight savings time conversion should
be applied. These values are set by tzset, not by the user program directly.
</help>

Did you check _daylight ?

Hans.
Back to top
Guest






PostPosted: Sun Apr 30, 2006 5:03 am    Post subject: Re: Invalid value of struct tm's 'tm_isdst'-element (when tr Reply with quote

Thanks for the answer:

Quote:
Did you check _daylight ?
Yes, I did. It is 1.


I found out the problem lies in the function
int _isDST (unsigned hour, unsigned yday, unsigned month, unsigned
year)
located inside the file timefunc.c.

A commentary inside it says

/* Month is either April or October. Up through 1986, the
starting
* day for DST is the last Sunday in April; after that it is
* the first Sunday in April. The last day of DST is the last
Sunday
* in October.
*/

This seems not to be correct:

According to another source in the internet: since 1996 summertime in
Germany begins at the last sunday in march 2:00 MEZ and ends at the
last sunday in october at 3:00 MESZ.


Checking this under windows, this seems correct (at least in the
recent years):: E.g. setting current date to 26th march 2006 and time
to 1:59:59, 2 secs later windows displays time as 3:00:01.


? How can I check in which country the current computer is located in,
to be able to calculate the summer-time individually (or displaying a
message, that the summertime-calculation is not available for this
country)? (I suppose _timezone would be helpful, but not enough,
because some nearby countries handle summertime differently too).

Thank you,

Michael
Back to top
vavan
Guest





PostPosted: Tue May 02, 2006 6:03 am    Post subject: Re: Invalid value of struct tm's 'tm_isdst'-element (when tr Reply with quote

On Sun, 30 Apr 2006 05:45:45 +0200, <MR> wrote:

Quote:
This seems not to be correct:

there is a long-standing bug in bcb rtl related to DST handling.
recently I sent fixed sources to borland engineer currently assigned
to rtl tasks. I hope borland finally will include those fixes. I can
send them to you if you show your email. you'll need to rebuild rtl
though. I personally couldn't rebuilt bds rtl yet (make failed)

--
Vladimir Ulchenko aka vavan
Back to top
AlexB
Guest





PostPosted: Tue May 30, 2006 12:22 pm    Post subject: Re: How to avoid this Reply with quote

Clayton Arends wrote:
Quote:
Do you have a QC link or other reference to point me to?

At your service: 19753

Alex.
Back to top
yu xing
Guest





PostPosted: Tue May 30, 2006 12:45 pm    Post subject: Re: Codeguard Error Reply with quote

your code causes memory leak!
you should use
//
delete []Columns;
Back to top
Clayton Arends
Guest





PostPosted: Tue May 30, 2006 1:05 pm    Post subject: Re: How to avoid this Reply with quote

*gulp*

Thanks for that scary bedtime story. Now I'm going to go to sleep and have
nightmares over all of the places I've used this notation. This might
explain some tiny memory leaks in my apps that I've never been able to quite
figure out.

Now, to satisfy my limited scope requirement:

{
int p;
while ((p = string.Pos("$")) != 0)
{
}
}

-or even uglier/scarier-

for (int p; (p = string.Pos("$")) != 0; )
{
}

Thanks for bringing this to my attention,

- Clayton
Back to top
Ed Mulroy
Guest





PostPosted: Tue May 30, 2006 5:19 pm    Post subject: Re: How to avoid this Reply with quote

Quote:
Now, to satisfy my limited scope requirement:

{
int p;
while ((p = string.Pos("$")) != 0)
{
}
}

FWIW:
I did things like that for years, especially in older C code.

One day I decided to investigate it further, examining the generated code.
I found that the compiler is fairly good at limiting the scope. 'p' would
normally be a register althoug a memory location might be used depending
upon how involved the code in the loop is. After the loop it was used for
something else (if needed).

Your scope-limiting concerns mainly address your own coding. Judging from
the amount of time you've been posting on here and the content of your
posts, I doubt that is much of a problem for you.

However if someone else gets to modify your code then I take that back :-)

.. Ed

Quote:
Clayton Arends wrote in message
news:447bfca2$1 (AT) newsgroups (DOT) borland.com...
*gulp*

Thanks for that scary bedtime story. Now I'm going to go to sleep and
have nightmares over all of the places I've used this notation. This
might explain some tiny memory leaks in my apps that I've never been able
to quite figure out.

Now, to satisfy my limited scope requirement:

{
int p;
while ((p = string.Pos("$")) != 0)
{
}
}

-or even uglier/scarier-

for (int p; (p = string.Pos("$")) != 0; )
{
}

Thanks for bringing this to my attention,
Back to top
Clayton Arends
Guest





PostPosted: Tue May 30, 2006 9:09 pm    Post subject: Re: How to avoid this Reply with quote

"Ed Mulroy" <dont_email_me (AT) bitbuc (DOT) ket> wrote in message
news:447c3867$1 (AT) newsgroups (DOT) borland.com...

Quote:
Your scope-limiting concerns mainly address your own coding.

Quite true. My main concern in cases like this is in clarifying the intent
of my code.

Quote:
Judging from the amount of time you've been posting on here and the
content of your posts, I doubt that is much of a problem for you.

Thanks for that.

- Clayton
Back to top
Bob Gonder
Guest





PostPosted: Tue May 30, 2006 10:00 pm    Post subject: Re: puttext()-problems, if DOS-Box is larger than dos-box-sc Reply with quote

<MR> wrote:

Quote:
How can I get the (x,y) coordinate to use for puttext(), if I want to
write to let's say the current cursor-position?

I think you need to apply winleft and wintop to curx and cury.
Also, your rectangle might need clipping by winright and winbottom

Quote:
struct text_info TextInfoStartup;
gettextinfo(&TextInfoStartup);
CurrentTextAttrib=TextInfoStartup.attribute;
CurrentCursorX=TextInfoStartup.curx;
CurrentCursorY=TextInfoStartup.cury;

CurrentCursorX=TextInfoStartup.curx - TextInfoStartup.winleft;
CurrentCursorY=TextInfoStartup.cury - TextInfoStartup.wintop;

Quote:
Perhaps there is an altternative for puttext()!?

Yes, the Win Console functions.
GetConsoleScreenBufferInfo()
SetConsoleCursorPosition()
WriteConsole()
And many more.
Back to top
Thomas Maeder [TeamB]
Guest





PostPosted: Wed May 31, 2006 1:10 am    Post subject: Re: Codeguard Error Reply with quote

yu xing <mail2yzx (AT) 126 (DOT) com> writes:

Quote:
your code causes memory leak!

Maybe. More exactly, his code has undefined behavior. A memory leak is
just one possible outcome.


Quote:
you should use
//
delete []Columns;

Correct.
Back to top
AlexB
Guest





PostPosted: Wed May 31, 2006 8:35 am    Post subject: Re: How to avoid this Reply with quote

Clayton Arends wrote:
Quote:
Now I'm going to go to sleep and have nightmares ...

And it's only one thing among others.

How often do you browse through the list of QC reports about critical
bugs in codegeneration? Any normal programmer would go crazy with it.
But borland crew sleep "the sleep of the just" for years.

Take a look on this NG thread:

"Q: I would like to know what are the most famous applications developed
under BCB platform 5 or 6?

A: Keith Chuvala of the United Space Alliance (and a former TeamB
member) was a speaker at DevCon this week. One of his sessions
demonstrated the functionality of his team's "WorldMap" application,
which is developed exclusively in BCB for use by NASA on its space
shuttles and the International Space Station (ISS) for tracking
real-time orbital postitioning of shuttles, the IIS, satellites."

Astronauts are adventurous guys...

Alex.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Goto page 1, 2, 3 ... 30, 31, 32  Next
Page 1 of 32

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.