Re: [fpc-pascal] Is TFPList thread safe?

2014-10-07 Thread Michael Schnell
On 10/06/2014 05:55 PM, Dennis Poon wrote: function TThreadList.LockList: TList; begin Result:=FList; System.EnterCriticalSection(FLock); end; Yep. System.EnterCriticalSection is a procedure variable that is set according to the OS and arch the project is compiled for. In

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Michael Schnell
On 10/02/2014 03:59 PM, Xiangrong Fang wrote: , not replace TFPList with TThreadList, for simplicity and performance reason... I don't suppose it will be possible to beat TThreadList performance by any home-brew Pascal code, which is same is not insecure. -Michael

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Michael Schnell
On 10/02/2014 04:23 PM, Xiangrong Fang wrote: I need my program to work on both Linux and Windows, can I still use FUTEX? I did not recommend to use FUTEX yourself. Futex is a rather complicated thingy that needs ASM for a combination of atomic user land operations and system calls (that

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Michael Schnell
On 10/02/2014 05:03 PM, Xiangrong Fang wrote: For Windows, critical sections are lighter-weight than mutexes. Mutexes can be shared between processes, but always result in a system call to the kernel which has some overhead. Critical sections can only be used within one

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Marco van de Voort
In our previous episode, Michael Schnell said: For Critical Sections, FPC has the TCriticalSection object, is there a TMutex object? AFAI understand, CriticalSection is the Delphi/fpc name for POSIX-Mutex. Critical sections are bound to the owning process under Windows, while Windows

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Michael Schnell
On 10/06/2014 12:18 PM, Marco van de Voort wrote: So critical section is equal to posix mutex with PTHREAD_PROCESS_PRIVATE attribute. Thanks for the clearness ! (The OP of course just wants just this - synchronization between threads of a single application.) -Michael

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Marco van de Voort
In our previous episode, Michael Schnell said: So critical section is equal to posix mutex with PTHREAD_PROCESS_PRIVATE attribute. Thanks for the clearness ! (The OP of course just wants just this - synchronization between threads of a single application.) On *nix for critical section,

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-06 Thread Dennis Poon
Michael Schnell wrote: On 10/02/2014 03:59 PM, Xiangrong Fang wrote: , not replace TFPList with TThreadList, for simplicity and performance reason... I don't suppose it will be possible to beat TThreadList performance by any home-brew Pascal code, which is same is not insecure. But I

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-03 Thread José Mejuto
El 03/10/2014 a las #4, Xiangrong Fang escribió: I don't intend to do any optimization. I just think that I need to enter a critical section, add item to the list, then leave the critical section. Hello, You must protect with a CriticalSection, Add and any other kind of access, like

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Michael Van Canneyt
On Thu, 2 Oct 2014, Xiangrong Fang wrote: Hi, I would like to know if TFPList is thread-safe or not? And if I make a component thread-safe by using critical sections etc. Is the performance penalty noticeable?  TFPList is not thread-safe. You need to use TThreadList if you want a

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Michael Schnell
On 10/02/2014 03:02 AM, Xiangrong Fang wrote: Hi, I would like to know if TFPList is thread-safe or not? And if I make a component thread-safe by using critical sections etc. Is the performance penalty noticeable? For a class, Thread save is not that easily defined. e.g.: It can be fully

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
2014-10-02 14:16 GMT+08:00 Michael Van Canneyt mich...@freepascal.org: TFPList is not thread-safe. You need to use TThreadList if you want a thread-safe list. Critical sections use OS calls, so there is always a performance penalty. I think the only thread-critical operation I need is to

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Michael Schnell
On 10/02/2014 08:16 AM, Michael Van Canneyt wrote: Critical sections use OS calls, so there is always a performance penalty. That is what Futex is made for. AFAIR, in Linux, the fpc RTL calls the pthread library mutex... function. This library uses Futex, if the arch supports that, and uses

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
2014-10-02 22:09 GMT+08:00 Michael Schnell mschn...@lumino.de: AFAIR, in Linux, the fpc RTL calls the pthread library mutex... function. This library uses Futex, if the arch supports that, and uses the plain old MUTEX system call if the arch does not support FUTEX. I need my program to work

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
2014-10-02 22:23 GMT+08:00 Xiangrong Fang xrf...@gmail.com: 2014-10-02 22:09 GMT+08:00 Michael Schnell mschn...@lumino.de: AFAIR, in Linux, the fpc RTL calls the pthread library mutex... function. This library uses Futex, if the arch supports that, and uses the plain old MUTEX system call

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Jonas Maebe
On 02 Oct 2014, at 15:59, Xiangrong Fang wrote: I think the only thread-critical operation I need is to add item to the list, so I will use critical section myself, not replace TFPList with TThreadList, for simplicity and performance reason... It will make your program unstable (adding an

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
2014-10-02 23:07 GMT+08:00 Jonas Maebe jonas.ma...@elis.ugent.be: On 02 Oct 2014, at 15:59, Xiangrong Fang wrote: It will make your program unstable (adding an element to an fplist can cause the entire internal array to move, so if you are in the middle of a read operation at the same time,

[fpc-pascal] Is TFPList thread safe?

2014-10-01 Thread Xiangrong Fang
Hi, I would like to know if TFPList is thread-safe or not? And if I make a component thread-safe by using critical sections etc. Is the performance penalty noticeable? Thanks. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org