Author Topic: [Solved] Multi threading on OSX, semaphore init error  (Read 4690 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 540
    • MarcusFernstrom.com
[Solved] Multi threading on OSX, semaphore init error
« on: August 25, 2015, 02:30:57 pm »
I have a multi-threaded application that runs fine on Windows, now I'm trying to make sure it also runs on Mac.

It starts fine, but when I click the button which starts a thread, I get an error:  raised exception "EThread" with message: Semaphore init failed (possibly too many threads)

I've looked around the forums and other places, but haven't found anything that has helped.

Is there any specific things one should do, to get multi-threading working on OSX?
« Last Edit: August 25, 2015, 11:39:11 pm by Trenatos »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1071
Re: Multi threading on OSX, semaphore init error
« Reply #1 on: August 25, 2015, 02:36:31 pm »
Make sure you have the cthreads unit as first unit in the uses clause of your main program. If that's already the case, then your problem will be fixed in FPC 3.0, as it completely removes the use of semaphores.

FPC 3.0rc1 should be announced later today.

Trenatos

  • Hero Member
  • *****
  • Posts: 540
    • MarcusFernstrom.com
Re: Multi threading on OSX, semaphore init error
« Reply #2 on: August 25, 2015, 02:41:49 pm »
@Jonas, when I have the cthreads in my {i$fdef darwin}, I immediately get an error when trying to run the program: Raised exception class 'RunError(211)' at address 46758C

balazsszekely

  • Guest
Re: Multi threading on OSX, semaphore init error
« Reply #3 on: August 25, 2015, 02:52:44 pm »
Lazarus Menu-->Project-->View Project Source. It should look like this:

Code: [Select]
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces,
  //other units here
  { you can add units after this };

//...

Trenatos

  • Hero Member
  • *****
  • Posts: 540
    • MarcusFernstrom.com
Re: Multi threading on OSX, semaphore init error
« Reply #4 on: August 25, 2015, 03:04:28 pm »
@GetMem, checked and that's what it already looks like.

Trenatos

  • Hero Member
  • *****
  • Posts: 540
    • MarcusFernstrom.com
Re: Multi threading on OSX, semaphore init error
« Reply #5 on: August 25, 2015, 03:55:48 pm »
Success!

I had not added -dUseCThreads in the compiler options.

 

TinyPortal © 2005-2018