Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #5380
| From | Martin <spam@spam.spam> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: Thread safe code - any caveats? |
| References | (1 earlier) <51c03d5a$0$59644$c3e8da3$66d3cc2f@news.astraweb.com> <M9Xvt.159290$xf1.107935@fx16.fr7> <51c08d89$0$1698$c3e8da3$14a0410e@news.astraweb.com> <yLdwt.151237$OL1.2491@fx13.fr7> <51c194b1$0$38134$c3e8da3$f6268168@news.astraweb.com> |
| Message-ID | <vMgwt.107261$4C2.78184@fx23.fr7> (permalink) |
| Date | 2013-06-19 12:40 +0100 |
Here we go Ginny
Thanks
Martin
FUNCTION DelMonitor (ptrCtrl AS PTR) AS LONG STRICT
LOCAL TBarList AS bcBarList, ;
TBarCode AS bcBarCode, ;
TOrder AS bcOrder, ;
TDelList AS bcDelList, ; //, a as csocket
strCtrl AS CheckThreadControl, ;
pszRack AS PSZ, ;
pszBat AS PSZ, ;
pszProc AS PSZ, ;
cOrder AS STRING, ;
cCust AS STRING, ;
cBarCode AS STRING, ;
cProc AS STRING, ;
nRack AS DWORD, ;
lOk AS LOGIC, ;
nCount AS DWORD
strCtrl := ptrCtrl
flog('a')
IF strCtrl.lLive
RETURN 0
ENDIF
flog('b')
DynLock()
strCtrl.lLive := TRUE
// GUI Less servers
TBarList := bcBarList{}
TBarCode := bcBarCode{}
TOrder := bcOrder{}
TDelList := bcDelList{}
nCount := 0
// big loop in here
DO WHILE !strCtrl.lToClose
IF nCount > 3
EXIT
ENDIF
IF strCtrl.lToClose
EXIT
ENDIF
IF strCtrl.lWait
// pause here
sleep(200)
nCount ++
LOOP
ENDIF
// If I have data check the batch
nRack := GetpszRack(strCtrl)
IF nRack = 0
nCount ++
sleep(200)
LOOP
ENDIF
DO CASE
CASE nRack = 1
pszRack := strCtrl.pszRack1
pszBat := strCtrl.pszBat1
pszProc := strCtrl.pszProc1
strCtrl.pszRack1 := Null_PSZ
CASE nRack = 2
pszRack := strCtrl.pszRack2
pszBat := strCtrl.pszBat2
pszProc := strCtrl.pszProc2
strCtrl.pszRack2 := Null_PSZ
CASE nRack = 3
pszRack := strCtrl.pszRack3
pszBat := strCtrl.pszBat3
pszProc := strCtrl.pszProc3
strCtrl.pszRack3 := Null_PSZ
ENDCASE
nCount := 0
IF TDelList:Seek(pszRack)
TBarCode:SetOrder(2)
TBarList:SetOrder(2)
// Check the order
cOrder := TDelList:FieldGet(#DEL_Order)
IF TOrder:Seek(cOrder)
cCust := Torder:FieldGet(#OD_CustNo)
ELSE
cCust := 'xxxxxxxxxx'
ENDIF
cProc := PSZ2String(pszProc)
lOk := TRUE
DO WHILE TDellist:FieldGet(#DEL_Key) == pszBat .AND. !TDellist:EoF
cOrder := TDelList:FieldGet(#DEL_Order)
IF TOrder:Seek(cOrder)
IF cCust <> Torder:FieldGet(#OD_CustNo)
EXIT
ENDIF
// Check the barcodes
TBarCode:Seek(cOrder)
DO WHILE TBarCode:FieldGet(#BC_Order) == cOrder .AND.
!TBarCode:EoF
cBarcode := TBarCode:FieldGet(#BC_Key)
IF !TBarList:Seek(cProc+cBarcode)
lOk := FALSE
EXIT
ENDIF
IF TBarList:FieldGet(#PL_Qty) <= 0
lOk := FALSE
EXIT
ENDIF
TBarCode:Skip(1)
ENDDO
ENDIF
TDelList:Skip(1)
ENDDO
IF lOk
PostMessage(strCtrl.hWindow,WM_APP+110,nRack,0)
flog('ok')
ELSE
PostMessage(strCtrl.hWindow,WM_APP+111,nRack,0)
flog('not')
ENDIF
TBarCode:SetOrder(1)
TBarList:SetOrder(1)
ENDIF
ENDDO
DynUnlock()
TDelList:Close()
TOrder:Close()
TBarCode:Close()
TBarList:Close()
strCtrl.lLive := FALSE
flog('c')
RETURN 0
On 19/06/2013 12:24, Ginny Caughey wrote:
> I don't remember seeing the VO code that runs in a worker thread then.
> If you want to show it I may be able to make some suggestions. I had one
> app that ran 4 worker threads accessing DBF files 24x7 for several years
> at several sites, so it is certainly possible, but when I replaced that
> functionality with C# apps, I used separate processes rather than
> separate threads even though .NET has better thread handling than the VO
> runtime.
>
> Ginny
>
> "Martin" wrote in message news:yLdwt.151237$OL1.2491@fx13.fr7...
>
> Hello Ginny
>
> That is XBase++ code!
>
> See thread crashing messages for the VO Code
>
> Thanks
>
> Martin
>
> On 18/06/2013 17:41, Ginny Caughey wrote:
>> I'm not sure what you mean by neatness of code, but I think you
>> understand what I mean about threads being sort of the last choice to
>> use. ;-)
>>
>> Given that this is VO, I'd try very hard to make this a separate app
>> instead of a separate thread. The code you're showing me uses
>> manipulates strings, for example. It looks like it wants to do something
>> on the UI thread too, which you can't do from a worker thread. Instead
>> you could pass a Windows message to the UI thread, which its dispatcher
>> could interpret in some way. I'm also not seeing where you open and
>> close the database on the worker thread. You can't manipulate the same
>> workarea safely across threads.
>>
>> See my Serial class for an example of using a worker thread safely.
>>
>> Ginny
>>
>> "Martin" wrote in message news:M9Xvt.159290$xf1.107935@fx16.fr7...
>>
>> Thanks Ginny
>>
>> The main reason is neatness of code and communications.
>>
>> I will be sending the rack number in a PSZ in a struct but will need to
>> search a DBF for it.
>>
>> This is the code I am converting, this is in XBase++, but need it in VO
>> 2.8. AS you can see it is not especially long, and is stable, but I
>> can't link in huge amounts of VO into Xbase++
>>
>> cBat := Left(cRack,10)
>> // Now we could monitor order or rack
>> IF TDelList->(DBSeek(cRack))
>> TBarCode->(OrdSetFocus(2))
>> TBarList->(OrdSetFocus(2))
>>
>> // Check the order
>> cOrder := TDelList->DEL_Order
>> IF TOrder->(DBSeek(cOrder))
>> cCust := Torder->OD_CustNo
>> ELSE
>> cCust := 'xxxxxxxxxx'
>> ENDIF
>>
>> lOk := .T.
>> DO WHILE TDellist->DEL_Key == cBat .AND. !TDellist->(EoF())
>> cOrder := TDelList->DEL_Order
>> IF TOrder->(DBSeek(cOrder))
>> IF cCust <> Torder->OD_CustNo
>> EXIT
>> ENDIF
>>
>> // Check the barcodes
>> TBarCode->(DBSeek(cOrder))
>> DO WHILE TBarCode->BC_Order == cOrder .AND. !TBarCode->(EoF())
>> cBarcode := TBarCode->BC_Key
>>
>> IF !TBarList->(DBSeek(cProc+cBarcode))
>> lOk := .F.
>> EXIT
>> ENDIF
>>
>> IF TBarList->PL_Qty <= 0
>> lOk := .F.
>> EXIT
>> ENDIF
>>
>> TBarCode->(DBSkip(1))
>> ENDDO
>> ENDIF
>> TDelList->(DBSkip(1))
>> ENDDO
>>
>> IF lOk
>> // Fully loaded!!!!
>> // Hit_Key('fully loaded')
>>
>> nPos := AT(cErr,'OPQRSTUVWXYZ')
>> SBeep(nPos,9,'WAV')
>> ENDIF
>>
>> TBarCode->(OrdSetFocus(1))
>> TBarList->(OrdSetFocus(1))
>> ENDIF
>>
>>
>>
>>
>>
>> On 18/06/2013 11:59, Ginny Caughey wrote:
>>> If you access DBF files, don't share the workarea with any other thread.
>>> Use normal multiuser access patterns.
>>> No dynamic data types such as strings that might trigger garbage
>>> collection.
>>> Seriously consider why this needs to be a separate thread instead of a
>>> separate app.
>>>
>>> HTH,
>>> Ginny
>>>
>>> "Martin" wrote in message news:WKWvt.136194$I84.63382@fx07.fr7...
>>>
>>> Got quite a bit on the go now, but need a thread with data access, also
>>> it may need to run continually.
>>>
>>> Anything I need to be careful with please?
>>>
>>> Tahnks
>>>
>>> Martin
>>
>
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-18 11:36 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-18 06:59 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-18 12:05 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-18 12:41 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-19 09:14 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-19 07:24 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-19 12:40 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-19 10:02 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-19 17:07 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-20 07:22 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-20 17:12 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-20 14:04 -0400
Re: Thread safe code - any caveats? "Martin \(BT\)" <martin-spam@btinternet.com> - 2013-06-20 20:27 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-21 06:54 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-21 15:39 +0100
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-21 15:54 +0100
Re: Thread safe code - any caveats? "Ginny Caughey" <gcaughey@online.hotmail.com> - 2013-06-21 12:12 -0400
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-21 17:15 +0100
Re: Thread safe code - any caveats? dlzc <dlzc1@cox.net> - 2013-06-19 08:04 -0700
Re: Thread safe code - any caveats? Martin <spam@spam.spam> - 2013-06-19 17:04 +0100
csiph-web