Results 1 to 6 of 6

Thread: MREWS, Semaphores, and Lazarus

  1. #1

    MREWS, Semaphores, and Lazarus

    I've been working on some backend code that will run on Windows, Linux, and MAC boxes. This wasn't at all a problem in Lazarus until I realized that I had to have some DB synchronization built into the application (some versions of SQLite aren't thread-safe).

    Of course I've read Martin Harvey's lessons on threading multiple times (had to when I converted them to go live) and am quite familiar with writing MREWS (basic one at http://www.eonclash.com/Tutorials/Mu...y1.1/Ch11.html would work here).

    Looking into it, there isn't really a good implementation (cross platform) of Semaphores (TSemaphore in some Linux versions, Pipes in MAC, API in Windows) within Lazarus. I don't actually need cross process communications, so I'm thinking of writing a simple spin lock based MREWS that supports an operation stack (Finish existing reads, start write, queue reads/writes, finish write, process queue). Just want to make sure that something like this doesn't already exist before I re-invent this particular wheel.

    Once complete, I'll post up for everyone of course

    - Jeremy

  2. #2

    Re: MREWS, Semaphores, and Lazarus

    I'm not really an expert on thread synchronizaiton primitives, but can't the BasicEvent* and RtlEvent* event functions be used?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Re: MREWS, Semaphores, and Lazarus

    I'll have to look into those and see how well they are supported. I also thought of using interlockedincrement and interlockeddecrement, but it seems those are "kernel" methods in Linux only and should not be used in user mode .

    If nothing else I can use CriticalSections and create my own spin locks (as I stated above). Guess I could also try testing it for a while on each platform to see what breaks LOL

    - Jeremy

  4. #4

    Re: MREWS, Semaphores, and Lazarus

    Quote Originally Posted by jdarling
    I'll have to look into those and see how well they are supported. I also thought of using interlockedincrement and interlockeddecrement, but it seems those are "kernel" methods in Linux only and should not be used in user mode .
    I don't believe that's the case. They are assembler functions and implemented in usermode for all platforms.
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524

    Re: MREWS, Semaphores, and Lazarus

    Just do what i do, use SDL. it's semaphores and mutexes work perfectly fine when used with Tthread.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  6. #6
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524

    Re: MREWS, Semaphores, and Lazarus

    In fact, why not just get the SDL source, extract the methods for the semaphores/mutexes for all fpc supported platforms and convert them to pascal? They can't be reliant on SDL threads implementation because I use them in my tthreads, SDL threads are buggy when you try to wait on terminate with jedi-sdl
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

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