Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A question on using Inform-PE
#7
I've used this semaphore to communicate between dozen instances.
Just start multiple times and type something in one of the instances...

Code: (Select All)
Const SEMFILE = "~semaphore."
Do
  n% = n% + 1
Loop Until Not _FileExists(SEMFILE + _ToStr$(n%))
_Title "Semaphore " + _ToStr$(n%)
Open SEMFILE + _ToStr$(n%) For Binary Access Write As #1

Do
  _Limit 100

  o% = 1
  Do While _FileExists(SEMFILE + _ToStr$(o%))
    If o% <> n% Then
      r$ = sread$(o%)
      If r$ <> "" Then Print o%; r$
    End If
    o% = o% + 1
  Loop
  _Title "Semaphore " + _ToStr$(n%) + "/" + _ToStr$(o% - 1)

  Select Case k$
    Case Chr$(27)
      Exit Do
    Case "l"
      swrite "this is a line, this is a line, this is a line !!!"
    Case Else
      swrite k$
  End Select
  k$ = InKey$

Loop

Close #1
Kill SEMFILE + _ToStr$(n%)
System

Sub swrite (k$)
  Put #1, , k$
End Sub

Function sread$ (o%)
  Static ps&(1000)
  Open SEMFILE + _ToStr$(o%) For Binary Access Read As #2
  new& = LOF(2) - ps&(o%)
  If new& > 0 Then
    k$ = Space$(new&)
    Get #2, ps&(o%) + 1, k$
    ps&(o%) = ps&(o%) + new&
    sread$ = k$
  End If
  Close #2
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply


Messages In This Thread
A question on using Inform-PE - by justsomeguy - Yesterday, 11:43 PM
RE: A question on using Inform-PE - by mdijkens - 4 hours ago



Users browsing this thread: 5 Guest(s)