none
New feature idea. RRS feed

  • General discussion

  • What the SB team should add, is some kind of locking features. Small Basic includes (not in the default library) threading features, so add the threading features (name them tasks. like in NQC) and add them to the defualt library.

     

    Sub DoSomeThings()

    SomeVariable = Tasks.MakeNewInterchangeVariable()

    BackgroundTonePlayer.Start()
    ForegroundAnimator.Start() 

    EndSub

     

     

    Task BackgroundTonePlayer()

    ...

    SomeVariable = 5

    BackgroundTonePlayer.Sleep(500)

    EndTask

     

     

    Task ForegroundAnimator()

    ...

    TextWindow.Write(SomeVariable)

    ForegroundAnimator.Sleep(499)

    EndTask

     

    The Primitive class that the variables are hold would have another field _isLockingVariable. If yes, it would cause (access o rmodify) to apply synclock.

    • Changed type Jacob Brown Saturday, December 10, 2011 11:46 AM
    Friday, December 9, 2011 8:44 PM

All replies

    1. Why add new Task when there is already Sub?
    2. What will check is the primitive locked in your code?
    3. Wouldn't it be much simpler to just add normal scope to variables? Just throw error if user isn't using variables properly.
    Friday, December 9, 2011 9:33 PM
  •  

     

    No, no, no, You misunderstood me.

     

    When the user writes:

    SBiPod.Start()

    Animator.Start()

    KeyboardListener.Start()

     

    Task SBiPod()

    While "True"

    ... user code

    EndWhile

    EndTask

     

    ... the Animator and KeyboardListener are defined like above also.

     

    THE IDEA is that tasks are run asynchronously (one by one, the background of SB runs them as separate threads), and subs synchronously (the code is stopped, the sub is executed, then the code is active).

    So in the example up, for a moment of time there are four  threads active (the main one - the one that runs the code from the beginning of file, the SBiPod task, Animator task, KeyboardListener task).

    When the code in a task ends (reaches EndTask) the task ends. In opposite of threads, a single task could be in two states (running or not) - You can't run a task in two or more instances. User's intereraction would be:

    • SBiPod.Start()    ' starts the task.   If SBiPod arleady running, does nothing.
    • SBiPod.Stop()     ' stops the task.   If stopped, does nothing.
    • SBiPod.IsRunning()    ' returns "true" or "false"

     

    So for question 1: subs are sync, tasks are async.

     

    Question 2: The SBCompiler will be redesigned to check (I have seen the in other languages, so don't say it isn't possible :-)):

    • If a variable is used only in sub or outer sub, compile normally.
    • If a variable is used only in a single task, (and only in that task), compile normally (there can't be two instances of SBiPod)
    • If a varibale is used in sub, outer sub and a task, OR a variable is used in two or more tasks, compile with surrounding:
      synclock(generatesomeSyncLock)
      someVarialbe = set
      get = someVarialbe        ''' or something like that
      end synclock

     

    Question 3: Scope is a bad idea.

    Saturday, December 10, 2011 11:46 AM
  • Changed to discussion.
    Saturday, December 10, 2011 11:47 AM