Recent

Author Topic: [RESOLVED] FileMode and multi-thread  (Read 6685 times)

bubulemaster

  • New Member
  • *
  • Posts: 47
[RESOLVED] FileMode and multi-thread
« on: February 05, 2010, 11:00:54 am »
Hi,

I just want know if FileMode variable is multi-thread safe or if I must use critical section.
I found nothing about this.

Thanks
« Last Edit: February 07, 2010, 05:53:47 pm by bubulemaster »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1071
Re: FileMode and multi-thread
« Reply #1 on: February 05, 2010, 01:02:17 pm »
I just want know if FileMode variable is multi-thread safe or if I must use critical section.
It is not thread safe. You can use a critical section, but in the long run it's probably better to use the routines from sysutils instead (http://www.freepascal.org/docs-html/rtl/sysutils/fileopen.html and friends)

bubulemaster

  • New Member
  • *
  • Posts: 47
Re: FileMode and multi-thread
« Reply #2 on: February 05, 2010, 04:20:57 pm »
Yes, but these routines map to the Windows (or Linux) API functions and return file handles, not normal Pascal file variables. No ?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1071
Re: FileMode and multi-thread
« Reply #3 on: February 05, 2010, 04:23:30 pm »
Indeed.

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 206
    • http://www.lazarus.freepascal.org
Re: FileMode and multi-thread
« Reply #4 on: February 06, 2010, 03:07:53 am »
Use TFileStream instead. It's simple once you get used to it, can be combined with lots of other stream classes (zip, memory), is thread safe and platform independently.

bubulemaster

  • New Member
  • *
  • Posts: 47
Re: FileMode and multi-thread
« Reply #5 on: February 07, 2010, 05:53:34 pm »
TFileStream is good idea ! Thanks

 

TinyPortal © 2005-2018