Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Thread program

Reply
Thread Tools

Thread program

 
 
takeshi honda
Guest
Posts: n/a
 
      11-03-2012
I'm trying to create a thread program according to this article.
http://www.codeproject.com/Articles/...C-Thread-Class

The sample code is a case that each thread processes easy quick tasks.
In this case I have no problem.
But I want two threads to do time consuming process such as recvfrom().
In this case threading program doesn't work well.

while(1){
thread1.Event(); // this is waiting recvfrom() return.
thread2.Event(); // this doesn't start until above process finishes.
}

I also tried ThreadTypeIntervalDriven as follows.

thread1.SetThreadType(ThreadTypeIntervalDriven,10) ;
thread2.SetThreadType(ThreadTypeIntervalDriven,10) ;

For some reason, this causes a crash of the program.

How can I create program which has two threads using recvfrom()?
 
Reply With Quote
 
 
 
 
Robert Miles
Guest
Posts: n/a
 
      11-03-2012
On Saturday, November 3, 2012 8:51:25 AM UTC-5, takeshi honda wrote:
> I'm trying to create a thread program according to this article.
>
> http://www.codeproject.com/Articles/...C-Thread-Class
>
> The sample code is a case that each thread processes easy quick tasks.
>
> In this case I have no problem.
>
> But I want two threads to do time consuming process such as recvfrom().
>
> In this case threading program doesn't work well.
>
>
> while(1){
> thread1.Event(); // this is waiting recvfrom() return.
> thread2.Event(); // this doesn't start until above process finishes.
> }
>
>
> I also tried ThreadTypeIntervalDriven as follows.
>
>
> thread1.SetThreadType(ThreadTypeIntervalDriven,10) ;
> thread2.SetThreadType(ThreadTypeIntervalDriven,10) ;
>
>
> For some reason, this causes a crash of the program.
>
> How can I create program which has two threads using recvfrom()?


There's another newsgroup, comp.programming.threads, which may be appropriate
for this question.

 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-03-2012
On Sat, 2012-11-03, Luca Risolia wrote:
> On 03/11/2012 14:51, takeshi honda wrote:
>> I'm trying to create a thread program according to this article.
>> http://www.codeproject.com/Articles/...C-Thread-Class

>
> Have you ever had a look at the C++11 standard for threads? That article
> seems obsolete.


Not so much because it doesn't rely on the C++11 standard -- you can't
expect everyone to use it already. But the code seems archaic at a
glance (BOOL, CThread, no namespace ...) so I'm skeptic too.

Surely there are better pre-C++11 examples out there. Boost?

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      11-03-2012
On Saturday, 3 November 2012 15:51:25 UTC+2, takeshi honda wrote:
> I'm trying to create a thread program according to this article.
> http://www.codeproject.com/Articles/...C-Thread-Class


I do not like the implementation at all. Reasons:
* No namespaces, all that crap goes to global namespace
* Naming conventions especially Hungarian crap like "m_dwThread" and even both prefix and verbose
telling what it is like "CMutexClass"
* No separate RAII Lock class instead there are separate Lock and Unlock methods of mutex, so no exception safety.
* etc.

You will learn bad habits from that code, delete it.
If your compiler has std::thread then use it.
If it does not have download boost and use boost::thread.

> How can I create program which has two threads using recvfrom()?


What you seem to need for that is actually boost::asio ... learn to use it.

 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      11-04-2012
On Nov 3, 5:12*pm, Öö Tiib <oot...@hot.ee> wrote:
> On Saturday, 3 November 2012 15:51:25 UTC+2, takeshi honda *wrote:
> > I'm trying to create a thread program according to this article.
> >http://www.codeproject.com/Articles/...C-Thread-Class

>
> I do not like the implementation at all. Reasons:
> * No namespaces, all that crap goes to global namespace
> * Naming conventions especially Hungarian crap like *"m_dwThread" and even both prefix and verbose
> * telling what it is like *"CMutexClass"


Sorry if this is a naive question, but - I thought the point of
namespaces was to avoid name clashes, so why does it matter that the
names are in the global namespace if they're horrible ones which you
presumably aren't going to want to use yourself?
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      11-04-2012
On 11/05/12 10:40, Paul N wrote:
> On Nov 3, 5:12 pm, Öö Tiib<oot...@hot.ee> wrote:
>> On Saturday, 3 November 2012 15:51:25 UTC+2, takeshi honda wrote:
>>> I'm trying to create a thread program according to this article.
>>> http://www.codeproject.com/Articles/...C-Thread-Class

>>
>> I do not like the implementation at all. Reasons:
>> * No namespaces, all that crap goes to global namespace
>> * Naming conventions especially Hungarian crap like "m_dwThread" and even both prefix and verbose
>> telling what it is like "CMutexClass"

>
> Sorry if this is a naive question, but - I thought the point of
> namespaces was to avoid name clashes, so why does it matter that the
> names are in the global namespace if they're horrible ones which you
> presumably aren't going to want to use yourself?


Some other library may be foolish enough to use them?

I agree the code looks like some awful 90s MFC mess.

--
Ian Collins
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-04-2012
On Sun, 2012-11-04, Paul N wrote:
> On Nov 3, 5:12*pm, Öö Tiib <oot...@hot.ee> wrote:
>> On Saturday, 3 November 2012 15:51:25 UTC+2, takeshi honda *wrote:
>> > I'm trying to create a thread program according to this article.
>> >http://www.codeproject.com/Articles/...C-Thread-Class

>>
>> I do not like the implementation at all. Reasons:
>> * No namespaces, all that crap goes to global namespace
>> * Naming conventions especially Hungarian crap like *"m_dwThread"
>> and even both prefix and verbose
>> * telling what it is like *"CMutexClass"

[several other reasons snipped by PN]

> Sorry if this is a naive question, but - I thought the point of
> namespaces was to avoid name clashes, so why does it matter that the
> names are in the global namespace if they're horrible ones which you
> presumably aren't going to want to use yourself?


You mean it's ok to skip namespaces if you choose really awful names
for everything?

Apart from that: namespaces aren't just for avoiding name clashes.
They also /group/ related names.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      11-05-2012
On Sunday, November 4, 2012 5:46:02 PM UTC-5, Paavo Helde wrote:
>
> I gather you are kind of flagellant person wanting to invent and use
>
> horrible ugly names in your everyday work. Unfortunately, most people are
>
> more comfortable and would like to use normal meaningful names instead.
>
> For example, the above link contains code for a class named CTask, which
>
> is not so horrible (sans the meaningless C prefix) and has a real danger
>
> of colliding with a name in another library of a similar mindset.
>
>
>
> Namespaces solve this dilemma quite neatly. You just put everything in a
>
> namespace which is unique/ugly enough and use short meaningful names
>
> inside the implementation in the namespace; in other code using this
>
> library you can use short namespace aliases or using directives
>
> (discouraged). E.g:



Is there a need for an on line registry of namespaces?



Brian
Ebenezer Enterprises -- making programming fun again.
http://webEbenezer.net
 
Reply With Quote
 
takeshi honda
Guest
Posts: n/a
 
      11-05-2012
Thank you everyone.

Unfortunately, I do program in severe environment where neither std::threadnor boost exists. I am not an admin of the server.

Do you have any idea for this solution?

2012年11月3日土曜日 22時51分25秒 UTC+9 takeshi honda:
> I'm trying to create a thread program according to this article.
>
> http://www.codeproject.com/Articles/...C-Thread-Class
>
>
>
> The sample code is a case that each thread processes easy quick tasks.
>
> In this case I have no problem.
>
> But I want two threads to do time consuming process such as recvfrom().
>
> In this case threading program doesn't work well.
>
>
>
> while(1){
>
> thread1.Event(); // this is waiting recvfrom() return.
>
> thread2.Event(); // this doesn't start until above process finishes.
>
> }
>
>
>
> I also tried ThreadTypeIntervalDriven as follows.
>
>
>
> thread1.SetThreadType(ThreadTypeIntervalDriven,10) ;
>
> thread2.SetThreadType(ThreadTypeIntervalDriven,10) ;
>
>
>
> For some reason, this causes a crash of the program.
>
>
>
> How can I create program which has two threads using recvfrom()?


 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      11-06-2012
On Monday, November 5, 2012 12:00:19 AM UTC-6, Paavo Helde wrote:
>
> No, we do not need another ICANN, if that's what you mean. If at worst all
>
> 7G people suddenly started to code in C++, then we could just insert UUIDs
>
> in all namespace names.
>
>


I don't like the idea of adding UUID to names.
Names should be meaningful.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to implement per-thread timer in a multi-thread program? liu yang C Programming 4 07-28-2008 09:12 PM
Terminating a thread from the main thread Charles A. Lackman ASP .Net 3 12-09-2004 02:12 PM
"Thread was being aborted" error from WebApp using Thread.Sleep. Stephen Miller ASP .Net 3 07-01-2004 11:50 PM
Terminating program run from thread (not just the thread) Jeffrey Barish Python 0 05-28-2004 02:02 AM
perl 5.8.2/3 - thread started by a thread pawo Perl 0 02-16-2004 01:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57