[fpc-devel] POSIX threads and classes

Артем Смирнов smirnoffjr at gmail.com
Tue May 8 17:33:50 CEST 2007


Yeah, this one work correctly. Thanks!

2007/5/8, Helmut Hartl <helmut.hartl at firmos.at>:
> >  > fpc 2.0.4, opensuse 10.2, glibc-2.4-31.1
>
> You may try this version of your program
> -----
> program Project1;
>
> {$mode objfpc}{$H+}
>
> uses
>  UnixType,pthreads;
>
> type
>
> TCondv = class
> private
>    Cond : UnixType.pthread_cond_t;
>    CAttr : UnixType.pthread_condattr_t;
> public
>   constructor Create;
>   destructor Destroy; override;
> end;
>
> {TCondv}
> constructor TCondv.Create;
> begin
>   pthread_condattr_init(@CAttr);
>   pthread_cond_init(@Cond, @CAttr);
> end;
>
>
> destructor TCondv.Destroy;
> begin
>   inherited;
>   pthread_cond_destroy(@Cond);
>   pthread_condattr_destroy(@CAttr);
> end;
> {TCondv}
>
> var
>   obj1 : TCondv;
>   obj2 : TCondv;
> begin
>   obj1 := TCondv.Create;
>   obj2 := TCondv.Create;
>   obj1.Destroy;
>   obj2.Destroy;
> end.
> ---------------
>
>
> I had bad experiences with types differently declared in pthreads and
> UnixTypes.
> Namely the following:
>
> In pthread:
>
>   pthread_cond_t = record
>     __c_lock: _pthread_fastlock;
>     __c_waiting: _pthread_descr;
>   end;
>
> In UnixType: (ptypes.inc)
>
>   pthread_cond_t = record
>     __c_lock: _pthread_fastlock;
>     __c_waiting: pointer;
>     __padding:
> array[0..48-1-sizeof(_pthread_fastlock)-sizeof(pointer)-sizeof(clonglong
> )] of byte;
>     __align: clonglong;
>   end;
>
>
> A call like: i:=pthread_cond_timedwait(@FSignal, @MMutex, at tim);
> Fails with the first version (EINVAL), but succedes with the second one.
>
>
> HTH,
>  helmut
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>



More information about the fpc-devel mailing list