• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Multiprocessor problem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiprocessor problem?


  • Subject: Re: Multiprocessor problem?
  • From: Justin Walker <email@hidden>
  • Date: Tue, 18 Mar 2003 13:04:42 -0800

On Tuesday, Mar 18, 2003, at 01:40 US/Pacific, Mark Hunt wrote:

Justin
[snip]
It does seem strange, as (re-reading my original mail) it would imply
that I'm getting data before I've called recvfrom!

Is this 'app' purely user-mode, or does it have some kernel code
associated with it (that you have developed)?

I'm totally in user-land!

The code that calls "recvfrom" is in a single MPThread (based on the
BSDLLCtest sample code). The buffer array is allocated in my global
variable space.

My original code did this:

bcopy(&hdr->data[id].data, msg_queue[msg_put], count);
msg_queue[msg_put].size = count; // save packet size
msg_put += 1;
if(msg_put >= kBufferCount) msg_put = 0; // circular buffer

I spotted that there was a brief period when msg_put could point
outside the array, so I modified it so that it uses a local variable
(idx), instead of the "live" one, and updated msg_put by a single store:

idx = msg_put;
bcopy(&hdr->data[id].data, msg_queue[idx], count);
msg_queue[idx].size = count; // save packet size
idx += 1;
if(idx >= kBufferCount) idx = 0; // circular buffer
msg_put = idx;

The bug "seems" to have gone away, but I don't understand why this
would crash the Mac so comprehensively!
I'd be a lot happier if I knew.

As would the rest of us. Are you positive that the system locks up (no ping response, etc)?

The client thread that takes messages from the array uses a separate
msg_get index - the only access to msg_put in this thread is to compare
msg_put and msg_get for equality. The bug should only have caused a
re-read of the array contents!

BTW, does my buffer array need to be virtual memory safe? This MPThread
is just "ordinary" code outside the recvfrom, right?

The only reason your code needs to do something special in an MP/multithread world is that you would like it to operate correctly regardless of the platform. Theory tells us (remember theory? That which differs from practice, at least in practice) that your app should not affect the rest of the system.

The following sorts of things can affect the operation of the system, though: sharing memory between your code and other code; between threads of your app; and between your app and the kernel. There's a lot of sharing in Mac OS X, so it's not a slam-dunk to assure that alles ist g|t (or something like that).

Right now, I've no clue why things would go wrong there, but I haven't looked at your snippets for long enough to get one.

Cheers,

Justin

--
/~\ The ASCII Justin C. Walker, Curmudgeon-at-Large
\ / Ribbon Campaign
X Help cure HTML Email
/ \
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Multiprocessor problem? (From: Mark Hunt <email@hidden>)

  • Prev by Date: Re: Multiprocessor problem?
  • Next by Date: Re: Multiprocessor problem?
  • Previous by thread: Re: Multiprocessor problem?
  • Next by thread: Re: Multiprocessor problem?
  • Index(es):
    • Date
    • Thread