Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!ucsd!pacbell.com!att!cbnewsl!cbnewsk!ech From: ech@cbnewsk.att.com (ned.horvath) Newsgroups: comp.sys.mac.programmer Subject: Re: asynchronous question Message-ID: <1990Nov19.195110.2339@cbnewsk.att.com> Date: 19 Nov 90 19:51:10 GMT References: <1990Nov19.130139.35978@eagle.wesleyan.edu> Organization: AT&T Bell Laboratories Lines: 48 From article <1990Nov19.130139.35978@eagle.wesleyan.edu>, by rcook@eagle.wesleyan.edu: - Suppose I am making two asynchronous AppleTalk (or Device Manager, for that - matter) like this: - - var - MyParmBlock: ParmBlkPtr; - async: boolean; - - begin - ... - async := true; { make the calls asynchronously } - MyParmBlk := ParmBlkPtr(NewPtr(sizeof(ParmBlkPtr))); - - with MyParmBlock^ do - begin - { fill in data } - end; - err := SomeAppleTalkCall(MyParmBlock,async); - - with MyParmBlock^ do - begin - { fill in some more data } - end; - err := SomeOtherAppleTalkCall(MyParmBlock,async); - ... - end; - - Assuming the first AppleTalk call has not yet been completed by the time the - second call is made, is it safe to reuse MyParmBlock in this way? Ignore for - now the fact that I can't go back and check if the first call was completed - successfully. In other words, when something is placed in an I/O queue, is a - copy of the parameter block made or is a pointer to your data placed in the - queue instead? I assume it makes a copy, but I want to hear this from someone - who knows for sure. Thanks. Your intuition is wrong: your parameter block -- not a copy -- is linked into the I/O queue, and becomes the property of the OS until the request completes. A common technique is to set ioResult to 1 before the call (some drivers do this for you) since all valid completions are <= 0. You can then poll the ioResult field from your event loop if you don't feel up to doing an ioCompletion routine. Notice that the call "completes" -- i.e. never really gets started -- if the call returns anything but noErr (0). ALWAYS check the err return! =Ned Horvath=