Hi,
I'm porting a real-time application from Squeak to Dolphin (at first it was written in Visual Basic) and I have a problem with the processes priorities. Every time I run this code in a Workspace, I lock my image getting a "This program is not responding ... End now": m := RemoteMonitoringModel new. m connect. m startReading. I join an extract of the code at the end of this message. I have tried several process priority between 2 and userInterruptPriority but it doesn't change anything. I have also modified the length of the delay from 40 to 200 ms without success. Could someone help me to solve my problem or to point me in the right direction ? Thanks, Joseph ------- 8> ------- 8> ------- RemoteMonitoringModel>>connect reader := KPSSerialPortDriver onPort: comPort baud: CBR_9600 data: 8 parity: NOPARITY stop: ONESTOPBIT. ... RemoteMonitoringModel>>startReading reader startReading KPSSerialPortDriver>>startReading process ifNil: [self flush. process := [| delay | delay := Delay forMilliseconds: 200. [| bytes | bytes := serialPort readByteArray. (bytes notNil and: [bytes notEmpty]) ifTrue: [sharedQueue nextPut: bytes]. delay wait] repeat] forkAt: Processor userInterruptPriority] ------- 8> ------- 8> ------- |
Joseph,
> [| delay | > delay := Delay forMilliseconds: 200. > > [| bytes | > bytes := serialPort readByteArray. > (bytes notNil and: [bytes notEmpty]) ifTrue: [sharedQueue > nextPut: bytes]. > delay wait] > repeat] I'm guessing here, but a couple of ideas... What does #readByteArray do ? Presumably it is, or ends up calling, an external method. Perhaps that method blocks ? If it is not overlapped then it will block the entire Dolphin system even though it is running in a separate Dolphin Process. If it is overlapped then Dolphin will start an OS thread to execute the call, and continue normally, blocking only the calling Process until the thread has finished the external call. (In D6, the thread will be bound permanently to the Process for any subsequent calls, in D5 it is arbitrary which thread you get from the thread pool.) For one example of an overlapped call see CRTLibrary>>_spawnvp:cmdname:argv: Also, in Dolphin, you can't reuse Delay objects. They can only be #wait-ed on once. -- chris |
Chris,
> What does #readByteArray do ? Presumably it is, or ends up calling, an > external method. Perhaps that method blocks ? If it is not overlapped > then it > will block the entire Dolphin system even though it is running in a > separate > Dolphin Process. I think Joseph is using my Serial package. If so then the OS call is not overlapped but it does have a timeout facility that will force the call to return if any one of some predefined conditions is met (enough bytes, overall timeout and inter-character timeout). > Also, in Dolphin, you can't reuse Delay objects. They can only be > #wait-ed on > once. I would guess that's the trouble. When you try and reuse a Delay it returns immediately so Joseph will end up with a tight loop that hogs all the processing. A "Processor sleep: 200" inside the loop would be best. -- Ian Use the Reply-To address to contact me (limited validity). Mail sent to the From address is ignored. |
Ian Bartholomew wrote:
> Chris, > > >>What does #readByteArray do ? Presumably it is, or ends up calling, an >>external method. Perhaps that method blocks ? If it is not overlapped >>then it >>will block the entire Dolphin system even though it is running in a >>separate >>Dolphin Process. > > > I think Joseph is using my Serial package. If so then the OS call is not > overlapped but it does have a timeout facility that will force the call to > return if any one of some predefined conditions is met (enough bytes, > overall timeout and inter-character timeout). > > >>Also, in Dolphin, you can't reuse Delay objects. They can only be >>#wait-ed on >>once. > > > I would guess that's the trouble. When you try and reuse a Delay it returns > immediately so Joseph will end up with a tight loop that hogs all the > processing. A "Processor sleep: 200" inside the loop would be best. > That's it! Yes, I use Ian Serial package :-) and the "Processor sleep: 200" solves the problem. Thanks, Joseph |
Free forum by Nabble | Edit this page |