Author Topic: Possible race condition with _CLIPBOARD$  (Read 2432 times)

0 Members and 1 Guest are viewing this topic.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Possible race condition with _CLIPBOARD$
« on: December 11, 2019, 04:32:09 am »
Just noticed this in a new library I'm currently working on.
If _CLIPBOARD$ = variable$ and variable$ = _CLIPBOARD$ are too close to each other (time wise), then it may happen that you don't get out (partial or entirely) what you put into the clipboard. Obviously it also depends on the amout of data transferred. You maybe have to play with the number of loops and amount of chars to trigger the effect (depending on your system power). The _DELAY represents the instructions usually executed between a "copy" and "paste", but if these do not consume enough time, then you may get errors.

I'm not sure, if we shall prevent this effect with an internal delay added to the _CLIPBOARD$ = string command, as usually enough time will elapse between a "copy" & "paste". Maybe the best would be to just mention the possibility of the race condition in the Wiki, if "copy" & "paste" is to close to each other.

Code: QB64: [Select]
  1. FOR i& = 1 TO 1000
  2.     a$ = STRING$(300000, CHR$(RND * 90 + 33))
  3.     _CLIPBOARD$ = a$
  4.     '_DELAY 0.1
  5.     b$ = _CLIPBOARD$
  6.     IF b$ <> a$ THEN PRINT "error at loop"; i&
  7. NEXT i&
  8.  
  9.  
« Last Edit: December 14, 2019, 08:33:11 am by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

FellippeHeitor

  • Guest
Re: Possible race condition with _CLIPBOARD$
« Reply #1 on: December 11, 2019, 05:14:25 am »
Adding a mandatory delay after an API call wouldn't be right. If you're calling it in a loop, then it definitely would have to be done in your program.

Sounds like too specific an issue to be generalised in the wiki, in my opinion, but wikis are open works and unless someone chooses to edit your contribution out, it'll remain there.

Have you requested odin access to editing the wiki? https://www.qb64.org/forum/index.php?topic=1539.0

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Possible race condition with _CLIPBOARD$
« Reply #2 on: December 11, 2019, 11:41:37 am »
I experience the need for user delays with the various scree click statements, which allow us to click on various areas of the desktop, to take other actions, like fill in an online form. My suggestion would be along the same lines as Fell, in that these delay requirements be added to the wiki whenever possible. I think I might have even encountered the _CLIPBOARD problem you brought up, but that was when it first came out. I vaguely recall putting a .something delay in my routine, just as you did.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/