comp.lang.ada
 help / color / mirror / Atom feed
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: A common array
Date: Fri, 19 Dec 2003 22:23:46 -0500
Date: 2003-12-19T22:23:46-05:00	[thread overview]
Message-ID: <PdSdnSuq85YHXX6iRVn-ig@gbronline.com> (raw)
In-Reply-To: <fc116fae.0312190713.7182a4d6@posting.google.com>

Mr. J. wrote:
> I need to write a procedure that checks and prints  the prime numbers
> between 1 and m.
> The procedure gets 2 parameter, m- the numbers to check 1..m and n -
> the number of tasks to perform it.
> 
> each tak will check if a number is a prime number, and will update an
> array of booleans (size 1..m).
> At the end of all tasks the procedure prints the prime numbers.

Still not quite clear.  Does each task update one cell,
and no other task updates that cell?  IF that is the case,
then the cells do not need synchronization.

But IF one task implements a divisor, for example, setting
false every third cell, while another (for example) sets false
every fifth cell, then they could theoretically collide on
the fifteenth cell.  You could say, "it's so unlikely for
that to happen at the same time that I don't need to protect
the cells."  Or you could play it safe and make each cell a
protected object.  (Not the whole array--why lock all tasks
out of cell X just because somebody is writing to cell Y?)

However, IF each task is only writing False into Boolean
cells initialized to True, then a collision can't hurt anything.
It ends up False no matter who gets there first.

-- 
Wes Groleau
When all you have is a perl, everything looks like a string.




  reply	other threads:[~2003-12-20  3:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-17 22:08 A common array Ratson Janiv
2003-12-18  2:25 ` Stephen Leake
2003-12-18  3:10   ` Wes Groleau
2003-12-19 15:13     ` Mr. J.
2003-12-20  3:23       ` Wes Groleau [this message]
2003-12-19 15:10 ` Ratson Janiv
2003-12-20  9:24 ` Ratson Janiv
2003-12-20 18:06   ` Robert I. Eachus
2003-12-20 18:56 ` @Fill(NOSPAM)YourBrain.com
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox