Browse Source

* when typecasting the result of pthread_self, always call it using
pthread_self(), because it's a procvar under Linux and hence otherwise
the value of the procvar instead of the function result will be
taken (mantis #15821)

git-svn-id: trunk@15049 -

Jonas Maebe 15 years ago
parent
commit
4d8f578e4c
3 changed files with 21 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 2 2
      rtl/unix/cthreads.pp
  3. 18 0
      tests/webtbs/tw15821.pp

+ 1 - 0
.gitattributes

@@ -10316,6 +10316,7 @@ tests/webtbs/tw15777d.pp svneol=native#text/plain
 tests/webtbs/tw15777e.pp svneol=native#text/plain
 tests/webtbs/tw15777f.pp svneol=native#text/plain
 tests/webtbs/tw15812.pp svneol=native#text/plain
+tests/webtbs/tw15821.pp svneol=native#text/plain
 tests/webtbs/tw15843.pp svneol=native#text/plain
 tests/webtbs/tw15909.pp svneol=native#text/plain
 tests/webtbs/tw1592.pp svneol=native#text/plain

+ 2 - 2
rtl/unix/cthreads.pp

@@ -600,7 +600,7 @@ begin
 {$ifdef has_sem_open}
   { avoid a potential temporary nameclash with another process/thread }
   str(fpGetPid,semname);
-  str(ptruint(pthread_self),tid);
+  str(ptruint(pthread_self()),tid);
   semname:='/FPC'+semname+'T'+tid+#0;
   cIntSemaphoreInit:=cIntSemaphoreOpen(@semname[1],initvalue);
 {$else}
@@ -912,7 +912,7 @@ begin
 {$else}
   Result:=LoadPthreads;
 {$endif}
-  ThreadID := TThreadID (pthread_self);
+  ThreadID := TThreadID (pthread_self());
 {$ifdef DEBUG_MT}
   Writeln('InitThreads : ',Result);
 {$endif DEBUG_MT}

+ 18 - 0
tests/webtbs/tw15821.pp

@@ -0,0 +1,18 @@
+{$mode objfpc}{$H+}
+
+uses
+{$ifdef unix}
+  cthreads,
+{$endif}
+  Classes;
+
+begin
+  writeln('GetThreadID=', ptrint(GetThreadID));
+  writeln('GetCurrentThreadID=', ptrint(GetCurrentThreadId));
+  writeln('MainThreadID=', ptrint(MainThreadID));
+  if (GetThreadID<>GetCurrentThreadID) or
+     (MainThreadID<>GetThreadID) then
+    halt(1);
+end.
+
+