Results 1 to 22 of 22

Thread: libThread

  1. #1
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default libThread

    Plugin for Simba (Lape only) that exports TThread and TCriticalSection.

    Currently needs testing so I've denoted it as a pre-release, v2-alpha.

    This requires at least Simba 1.1.0!!

    Source: https://github.com/JohnPeel/libThread
    Download: https://github.com/JohnPeel/libThrea...s/tag/v2-alpha

    Example: https://gist.github.com/JohnPeel/39afeac6491d264a0816
    Last edited by Dgby714; 12-05-2014 at 04:55 AM.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  2. #2
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    661
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default

    Awesome! Thats is really great work!
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

  3. #3
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I am a multithread noob, but how does this compare to using the functions from Brandon? https://villavu.com/forum/showthread.php?t=108229
    Working on: Tithe Farmer

  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    I did export TMMLTimer also, which pretty much does achieves the same thing imo.

  5. #5
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

  6. #6
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    Why does this thread not include a mention to @Robert;?
    Mentioned right when I read this Thread, pun intended

  7. #7
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    Why does this thread not include a mention to @Robert;?
    Why would it?

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  8. #8
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    I am a multithread noob, but how does this compare to using the functions from Brandon? https://villavu.com/forum/showthread.php?t=108229
    No clue, his has more than just threading.

    I just exported TThread from FPC to Lape through a plugin.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  9. #9
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    I am a multithread noob, but how does this compare to using the functions from Brandon? https://villavu.com/forum/showthread.php?t=108229
    For the Threading API itself, there isn't a different. For locking/synchronisation however:

    Mutex vs. Critical Section.

    Mutexes use Kernel level synchronisation whereas Critical Sections are done in Usermode.
    Mutexes can be used across processes whereas Critical Sections cannot.
    Critical Sections are faster than Mutexes provided that there is no thread contention. Otherwise a critical section will allocate a semaphore or mutex object automatically and will have the same performance of a mutex.
    Mutexes are objects that are owned by a thread and as such, it blocks until that object itself is released. A mutex in other words is not a requirement but a warning..

    For a thread can optionally ignore the mutex and access the resource anyway. The same can be done for a CriticalSection if you try. With a mutex, it's easier to ignore. That being said, if you ignore a mutex or critical section, you might as well have not coded them in, in the first place.

    The TLapeThread supports termination and suspension whereas what I wrote has it "optional" provided you decide to use WinAPI to achieve it (which the TLapeThread does).

    I'm not sure that it is a good idea to export those simply for the fact that if you forcefully terminate a thread or suspend it in a bad/unexpected state, it will leak resources (upon termination) and deadlock (upon suspension). For suspension & termination, you should be using an atomic variable or a a regular variable with synchronisation aka "Condition Variable": http://en.wikipedia.org/wiki/Monitor_(synchronization) or http://msdn.microsoft.com/en-ca/libr...(v=vs.85).aspx.


    TLDR:
    Other than locking mechanisms, the functions are the same. With the exception of thread forceful termination & suspension, I'd use this for threading as it's just a threading only API.
    Last edited by Brandon; 07-10-2014 at 06:32 PM.
    I am Ggzz..
    Hackintosher

  10. #10
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Thanks, I will look into both plugins. Just for fun of course
    Working on: Tithe Farmer

  11. #11
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    For the Threading API itself, there isn't a different. For locking/synchronisation however:

    Mutex vs. Critical Section.

    Mutexes use Kernel level synchronisation whereas Critical Sections are done in Usermode.
    Mutexes can be used across processes whereas Critical Sections cannot.
    Critical Sections are faster than Mutexes provided that there is no thread contention. Otherwise a critical section will allocate a semaphore or mutex object automatically and will have the same performance of a mutex.
    Mutexes are objects that are owned by a thread and as such, it blocks until that object itself is released. A mutex in other words is not a requirement but a warning..

    For a thread can optionally ignore the mutex and access the resource anyway. The same can be done for a CriticalSection if you try. With a mutex, it's easier to ignore. That being said, if you ignore a mutex or critical section, you might as well have not coded them in, in the first place.

    The TLapeThread supports termination and suspension whereas what I wrote has it "optional" provided you decide to use WinAPI to achieve it (which the TLapeThread does).

    I'm not sure that it is a good idea to export those simply for the fact that if you forcefully terminate a thread or suspend it in a bad/unexpected state, it will leak resources (upon termination) and deadlock (upon suspension). For suspension & termination, you should be using an atomic variable or a a regular variable with synchronisation aka "Condition Variable": http://en.wikipedia.org/wiki/Monitor_(synchronization) or http://msdn.microsoft.com/en-ca/libr...(v=vs.85).aspx.


    TLDR:
    Other than locking mechanisms, the functions are the same. With the exception of thread forceful termination & suspension, I'd use this for threading as it's just a threading only API.
    Heh, Thanks for the clarification! So FPC's cross TThread's Terminate only supports windows?
    Hmm, Didn't know that...

    Haven't seen you in awhile =)

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  12. #12
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    Heh, Thanks for the clarification! So FPC's cross TThread's Terminate only supports windows?
    Hmm, Didn't know that...

    Haven't seen you in awhile =)

    Yeah I think it is only supported on Windows and mostly deprecated for Linux because of some security issues. Don't remember all the details but I'm fairly certain it uses WinAPI's "SuspendThread" & "ResumeThread" functions. I'll have to double check to be 100% sure.

    Yeah. Likewise I haven't seen you as well.

    EDIT: http://forum.lazarus.freepascal.org/...?topic=14920.0

    Apparently it never worked on Linux either.. But it's very easy to roll your own so no worries. I don't think you should remove it but that's your decision to make.

    It'd only be dangerous to unfamiliar developers with no WinAPI or threading background.. Other than that, I say keep it tbh. Everyone knows you shouldn't terminate a thread in a bad/unknown state but sometimes I find it necessary.
    Last edited by Brandon; 07-11-2014 at 07:04 AM.
    I am Ggzz..
    Hackintosher

  13. #13
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Yeah I think it is only supported on Windows and mostly deprecated for Linux because of some security issues. Don't remember all the details but I'm fairly certain it uses WinAPI's "SuspendThread" & "ResumeThread" functions. I'll have to double check to be 100% sure.

    Yeah. Likewise I haven't seen you as well.

    EDIT: http://forum.lazarus.freepascal.org/...?topic=14920.0

    Apparently it never worked on Linux either.. But it's very easy to roll your own so no worries. I don't think you should remove it but that's your decision to make.

    It'd only be dangerous to unfamiliar developers with no WinAPI or threading background.. Other than that, I say keep it tbh. Everyone knows you shouldn't terminate a thread in a bad/unknown state but sometimes I find it necessary.
    Ah, I see, hmmm, I should just export two properties to make it easier for people to implement their own suspending and terminating...

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  14. #14
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    @Olly; broke this library with a commit to Simba, will be writing a fix and recompiling soon.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  15. #15
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    @Olly; broke this library with a commit to Simba, will be writing a fix and recompiling soon.
    Aha, actually it was cynic.

  16. #16
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Olly View Post
    Aha, actually it was cynic.
    Cynic wrote the code for PS, you exported it to Lape, you broke it...

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  17. #17
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    I'm excited to try this but I'm sure I'm going to make crashes.

  18. #18
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    I am a multithread noob
    Yeah, me too. I recompiled the .dll after removing the broken part and got the test script to run fine, but guess I don't think I understand the concepts enough...I tried putting in more complex things for it to do besides add stuff to the x string, and Simba crashed every run.

    What exactly can you do within these threads/critical sections? Any function or procedure you want, or just simple tasks?

    Like I'm trying to multithread mouse movements, color searches, or perhaps script progress report updating, stuff like that. Does this library allow for this?
    I've read about safe thread management, the purposes of critical sections, but I'm having trouble applying that to Simba/Lape.

  19. #19
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Clarity View Post
    ...
    I couldn't get it to work :S

    Gotta wait on an update I guess.. Anyway.. it should be able to run any function.. Not sure if you have to declare it native or not. You might have to do some things via "getClient().blah.blah" instead of just the regular functions.

    There are many uses for threads..

    Painting live is a good use I guess.. Parallel sort, parallel calculations, Asynchronous sockets, etc..
    Last edited by Brandon; 10-04-2014 at 04:31 AM.
    I am Ggzz..
    Hackintosher

  20. #20
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    It will crash using any of MML's methods as they are not threadsafe, but you can use MML through the Client variable.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  21. #21
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    I've pushed a new "pre-release" on GitHub with changes to conform with current Simba exports.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  22. #22
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •