Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-09

Some details on BeginThread problem

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Robert Reimiller

The actual thread function starts out as :

function libthread (p : pointer) : longint ;
var
   q330 : pq330 ;
   readfds, writefds, exceptfds : tFdSet;
   timeout : timeval ;
   res : integer ;
   now_, diff : double ;
   new_ten_sec : longint ;
begin
   q330 := p ;

The compiler seems to reject any number of parameters to BeginThread. The errors
generated were:

Tool:0: libstrucs.pas:726: error: 36: Wrong number of parameters specified Tool:0: libstrucs.pas:727: error: 36: Wrong number of parameters specified Tool:0: libstrucs.pas:728: error: 25: Wrong number of parameters specified Tool:0: libstrucs.pas:729: error: 48: Wrong number of parameters specified

The lines in question were:

       threadid := beginthread(addr(libthread)) ;
       threadid := beginthread(addr(libthread), q330) ;
       BeginThread (addr(libthread), q330, threadid) ;
       BeginThread (NIL, DefaultStackSize, addr(libthread), q330, 0,
threadid) ;

The uses clause looks like: cthreads, baseunix, sockets, unix

What am I doing wrong?

Reply by email

Jonas Maebe
to Robert Reimiller
Robert Reimiller wrote 20 lines
Tool:0: libstrucs.pas:726: error: 36: Wrong number of parameters specified Tool:0: libstrucs.pas:727: error: 36: Wrong number of parameters specified Tool:0: libstrucs.pas:728: error: 25: Wrong number of parameters specified Tool:0: libstrucs.pas:729: error: 48: Wrong number of parameters specified The lines in question were: threadid := beginthread(addr(libthread)) ; threadid := beginthread(addr(libthread), q330) ; BeginThread (addr(libthread), q330, threadid) ; BeginThread (NIL, DefaultStackSize, addr(libthread), q330, 0, threadid) ; The uses clause looks like: cthreads, baseunix, sockets, unix What am I doing wrong?

You are using the default FPC mode as opposed to Delphi or MacPas mode (which Xcode template are you using? They all set macpas mode by default). Therefore the compiler interprets your use of "libthread" as a function call, and expects parameters after it. Either compile with -Sd or add {$mode delphi} at the top of your program, or change "addr(libthread)" into "@libthread" (it's interesting that addr behaves differently from @ though, I didn't know that).

Jonas

Reply by email

Robert Reimiller
to Jonas Maebe
Jonas Maebe wrote 7 lines
You are using the default FPC mode as opposed to Delphi or MacPas mode (which Xcode template are you using? They all set macpas mode by default). Therefore the compiler interprets your use of "libthread" as a function call, and expects parameters after it. Either compile with -Sd or add {$mode delphi} at the top of your program, or change "addr(libthread)" into "@libthread" (it's interesting that addr behaves differently from @ though, I didn't know that).

I'm using objfpc mode. Changing addr(libthread) into @libthread solved the problem.
I should have thought of that since I had the same problem with getting the address of a callback procedure. It now all compiles, now for the debugging......

Thanks,

Bob

Reply by email

Burkhard Carstens
to Robert Reimiller

Am Freitag, 8. September 2006 21:44 schrieb Robert Reimiller: [..]

Show quoted text 5 lines
I'm using objfpc mode. Changing addr(libthread) into @libthread solved the problem. I should have thought of that since I had the same problem with getting the address of a callback procedure. It now all compiles, now for the debugging......

From rtl/linux/tthread.inc line 189:

{ TThread }
constructor TThread.Create(CreateSuspended: Boolean;
                           const StackSize: SizeUInt =
DefaultStackSize);
begin
  // lets just hope that the user doesn't create a thread
  // via BeginThread and creates the first TThread Object in there!
  InitThreads;
...

I don't have mac os, no idea, if this applies there, too. Just thought, I should mention this ;-)

regards
Burkhard

Reply by email

Robert Reimiller
to Burkhard Carstens
Burkhard Carstens wrote 22 lines
Am Freitag, 8. September 2006 21:44 schrieb Robert Reimiller: [..] > I'm using objfpc mode. Changing addr(libthread) into @libthread > solved the problem. > I should have thought of that since I had the same problem with > getting the address of a callback procedure. It now all compiles, now > for the debugging...... > From rtl/linux/tthread.inc line 189: { TThread } constructor TThread.Create(CreateSuspended: Boolean; const StackSize: SizeUInt = DefaultStackSize); begin // lets just hope that the user doesn't create a thread // via BeginThread and creates the first TThread Object in there! InitThreads; ... I don't have mac os, no idea, if this applies there, too. Just thought, I should mention this ;-)

I think this only applies if you are using the tthread class, which I'm not. At least I've never had any problems on Delphi with 15 threads running :)

Reply by email