Jump to content

Is this behavior possible in AdlibRegister ?


Guest
 Share

Recommended Posts

Code:

HotKeySet('{ESC}','Exit1')
Func Exit1()
    Exit
EndFunc


$Inuse = 0

AdlibRegister('Test1',1000)
AdlibRegister('Test2',1000)


Func Test1()
    If $Inuse Then Return
    $Inuse = 1
    ConsoleWrite('Test1_1' & @CRLF)
    ConsoleWrite('Test1_2' & @CRLF)
    ConsoleWrite('Test1_3' & @CRLF)
    ConsoleWrite('Test1_4' & @CRLF)
    ConsoleWrite('Test1_5' & @CRLF)
    ConsoleWrite('Test1_6' & @CRLF)
    ConsoleWrite(@CRLF & @CRLF)
    $Inuse = 0
EndFunc


Func Test2()
    If $Inuse Then Return
    $Inuse = 1
    ConsoleWrite('Test2_1' & @CRLF)
    ConsoleWrite('Test2_2' & @CRLF)
    ConsoleWrite('Test2_3' & @CRLF)
    ConsoleWrite('Test2_4' & @CRLF)
    ConsoleWrite('Test2_5' & @CRLF)
    ConsoleWrite('Test2_6' & @CRLF)
    ConsoleWrite(@CRLF & @CRLF)
    $Inuse = 0
EndFunc


While 1
    Sleep(100)
WEnd

Is it possible that in an extreme case it will print something like this

Test1_1
Test2_1
Test1_2
Test2_2
Test1_3
Test2_3
Test1_4
Test2_4
Test1_5
Test2_5
Test1_6
Test2_6

In this case what needs to happen for this output is:

The  CPU performs the two functions about at the same time in this way:
Step 1) Execute line "If $Inuse Then Return" in function "Test1" -  The result is not return

Step 2) Execute line "If $Inuse Then Return" in function "Test2" -  The result is not return (This is bad ...)

Step 3) Execute the second line in "Test1"

Step 4) Execute the second line in "Test2"

 

And so on..

 

Is this behavior is possible?

Edited by Guest
Added code tags
Link to comment
Share on other sites

  • Moderators

gil900,

What have you done so far to test if this is possible? What checking code have you added to the base code you posted to see what is happening internally?

M23

P.S.  You have been here long enough to know that when you post code you should use Code tags.

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

What have you done so far to test if this is possible?

I just debugged a crash and according to the bedbug(I mean - Manual Investigation in my code and based on visual output behavior of the app.. If you understand what I mean) I did not found any failure in the code. the failure could happen only if this behavior really occurs.  I am using the app very often and this crash happened only once so it fits to this extreme case theory that normally does not happen

 

And I used Code tags.. Check your browser

 

EDIT:

 This could also happen if there is bug in UBound() function but this is very very unlikely

Edited by Guest
Link to comment
Share on other sites

  • Moderators

gil900,

So if you have checked and found no problem, how do expect anyone else to find one? Are we all supposed to run all sorts of tests to try and break the code? Be reasonable.

And as far as I know the 2 functions will run consecutively - never as you fear.

 I used Code tags

The OP now has code tags because I added them (check the edit remark at the bottom of the post) - you had used quotes.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

So if you have checked and found no problem, how do expect anyone else to find one?

I did not expect/ask that someone will run tests for hours or something like that ..
I just wanted to know if it is known that such behavior is possible (by a known bug or design choice) and this knowledge will help me somehow especially if there is confirmation to my concern.

 

The OP now has code tags because I added them (check the edit remark at the bottom of the post) - you had used quotes.

Ops, ok I didn't so that you edited the OP before

Edited by Guest
Link to comment
Share on other sites

Adlib functions don't run in their own thread, so no, what you describe in the OP simply can't happen. If adlibs can interrupt each other (I don't remember, but simple enough for you to check yourself) it would just be

Test1_1
Test2_1
Test2_2
Test2_3
Test2_4
Test2_5
Test2_6
Test1_2
Test1_3
Test1_4
Test1_5
Test1_6

 

Link to comment
Share on other sites

I knew that.

This is the lesson I learned -This is a dangerous idea to delete elements in Array inside Adlib function while a non-Adlib code may access the array.

Even something like

If $ArrayInUse Then Return
    $ArrayInUse = 1

Does not always prevents disaster. The safe way is not to delete elements while a non-Adlib code may access the array..

 

Thanks anyway.
I know what to do

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...