Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!samsung!ernie.viewlogic.com!news From: josh@concept.viewlogic.com (Josh Marantz) Newsgroups: comp.windows.x Subject: Re: How to simulate a blocked i/o in an event driven program? Message-ID: <1991Feb28.163227.402@viewlogic.com> Date: 28 Feb 91 16:32:27 GMT Sender: news@viewlogic.com (News Administrator) Organization: Viewlogic Systems, Inc. Lines: 67 The nested loop approach described by cs@cbnewsh.att.com is probably the best way to approach this problem in C. But when using Scheme, which support lexical scoping and first class procedures, there is a better way. Instead of "blocking", have the popup routine take a function as an argument, and run that function when the popup is activated. (define (SomeOtherCallBackThatGetsCalled ...) ; do your other stuff, computation, etc., ; and realize that you actually want to ; use the popupwindow() function (popwindow ... (lambda (UserResponse) ; some other computation, etc. ))) (popwindow ...) returns immediately, but its procedure argument gets called when the popup is terminated. The body of the procedure gets to use all the local variables in SomeOtherCallBackThatGetsCalled, and generally behave as if it was code that followed a blocking call to popwindow. No nested main loops are required. This can be done in C too, its just too clumsy to be used very much: typedef struct { ... Local variable declarations for SomeOtherCallbackThatGetsCalled ... } SomeOtherCallbackLocals; static void continuation(); void SomeOtherCallBackThatGetsCalled(...........) { SomeOtherCallbackLocals args; /* ** do your other stuff, computation, etc., ** and realize that you actually want to ** use the popupwindow() function */ . . . ZONK* UserResponse = popupwindw(........, continuation, &args); } static void continuation(UserResponse, args) ZONK* UserResponse; SomeOtherCallbackLocals *args; { . . . some more computation, etc.. . . } -- Joshua Marantz Viewlogic Systems, Inc. josh@viewlogic.com Why not pass the time by playing a little solitaire?