# MultiThreading in C++

**URL:** <https://www.ruby-forum.com/t/multithreading-in-c/84679>\
**Category:** Ruby\
**Created:** [February 6, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679 "2007-02-06T22:56:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 6, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/1 "2007-02-06T22:56:20Z")

</div>

Hi,

I am pretty new to multithreaded programming. I have a question with a  
hope someone can help me out.

I want to find distances between points using thread (Win MFC)

For instance distance from:  
p1 to p2, p3, p4, p5  
p2 to p1, p3, p4, p5  
p3 to p1, p2, p4, p5  
p4 to p1, p2, p3, p5  
p5 to p1, p2, p3, p4

with

p1(x1, y1) = p1(42.67,73.75)  
p2(x2, y2) = p2 (61.22, 149.9)  
p3(x3, y3) = p3(30.27, 97.73)  
p4(x4, y4) = p4(35.18,101.83)  
p5(x5, y5) = p5(41.15, 104.87)

using formular distance = square root (square (x2 - x1) + square (y2 -  
y1))

How can I do it and what is the best way to do this?

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 6, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/2 "2007-02-06T23:00:20Z")

</div>

The best way to solve this problem is not to use threads. It’s  
local-compute  
and local-memory bound so there is no capturable system latency. The  
problem  
appears to be parallelizable to some degree. If you are sure you’ll be  
running it on multi-processor or multicore hardware, then break up the  
dataset into multiple chunks, and run each one through a separate  
process.  
Threads add nothing here.

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 6, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/3 "2007-02-06T23:01:20Z")

</div>

ktxn1020 wrote:

> p3 to p1, p2, p4, p5
> 
> using formular distance = square root (square (x2 - x1) + square (y2
> 
> - y1))
> 
> How can I do it and what is the best way to do this?
> 
> Thanks in advance,

The best way is to do your school assignments yourself ;-), you will  
benefit from it in the future the great deal. Besides, it may be the  
wrong list as Ruby is discussed here.

Gennady.

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 6, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/4 "2007-02-06T23:03:20Z")

</div>

On 2/6/07, ktxn1020 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am pretty new to multithreaded programming. I have a question with a  
> hope someone can help me out.

First, this is a mailing list for the Ruby programming language, not  
C++. You would probably have better luck on a mailing list devoted to  
C++ programming, or on the comp.lang.c++ newsgroup.

Second, why are on earth are you using threads to solve the problem you  
stated?

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 7, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/5 "2007-02-07T15:34:47Z")

</div>

On Tue, 06 Feb 2007 22:59:41 +0100, Francis C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you are sure you’ll be  
> running it on multi-processor or multicore hardware, then break up the  
> dataset into multiple chunks, and run each one through a separate  
> process.  
> Threads add nothing here.

Threads for a single process only get scheduled on one of the cores?  
This  
is new to me, I thought at least on Windowsen, threads are the base  
scheduling unit.

David V.

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 6, 2007, 11:54pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/6 "2007-02-06T23:54:27Z")

</div>

On Wed, Feb 07, 2007 at 06:59:41AM +0900, Francis C. wrote:

> The best way to solve this problem is not to use threads. It’s local-compute  
> and local-memory bound so there is no capturable system latency. The problem  
> appears to be parallelizable to some degree. If you are sure you’ll be  
> running it on multi-processor or multicore hardware, then break up the  
> dataset into multiple chunks, and run each one through a separate process.  
> Threads add nothing here.

_applauds_

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 8, 2007, 1:54pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/7 "2007-02-08T13:54:14Z")

</div>

On Wed, 07 Feb 2007 17:28:59 +0100, Patrick H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On 2/7/07, David V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Threads for a single process only get scheduled on one of the cores?  
> > This  
> > is new to me, I thought at least on Windowsen, threads are the base  
> > scheduling unit.
> 
> Difference between a Windows (native) thread and a Ruby (green)  
> thread. The Ruby interpreter does not (yet) support native threads.

The whole thread is horribly off-topic with C++ and MFC being involved  
from the beginning from someone who thought ruby-talk is there to work  
out  
his homework. So the threads in my (equally off-topic) question are in  
fact native Win32 threads.

David V.

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 8, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/8 "2007-02-08T21:47:12Z")

</div>

On 2/8/07, David V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Wed, 07 Feb 2007 17:28:59 +0100, Patrick H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > On 2/7/07, David V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > Threads for a single process only get scheduled on one of the cores?  
> > > This  
> > > is new to me, I thought at least on Windowsen, threads are the base  
> > > scheduling unit.

Horribly offtopic reply: on Windows, the scheduling unit is what Windows  
calls a “thread” (and might be more properly termed a kernel thread or a  
light-weight process). Essentially the same deal on Linux. On Solaris  
it’s  
different, you have both LWPs and userland threads. To your point,  
windows  
threads within a process will get scheduled on multiple cores and/or  
processors (you can even tune their affinity for particular cores), but  
this  
adds nothing of value in the OP’s homework assignment. Partition the  
incoming dataset, schedule on multiple processes, and aggregate the  
result  
sets at the end. So much easier to debug than a threaded implementation.

---

<div class="post-metadata">

**Author:** ![ktxn1020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a8b319/32.png) [@ktxn1020](https://www.ruby-forum.com/u/ktxn1020)\
**Post date:** [February 7, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/multithreading-in-c/84679/9 "2007-02-07T17:30:03Z")

</div>

On 2/7/07, David V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Threads for a single process only get scheduled on one of the cores? This  
> is new to me, I thought at least on Windowsen, threads are the base  
> scheduling unit.

Difference between a Windows (native) thread and a Ruby (green)  
thread. The Ruby interpreter does not (yet) support native threads.

pth
