Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can an object know of it's existence?
Message
 
À
02/12/2003 18:35:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00855003
Message ID:
00855303
Vues:
24
>I wouldn't bank any money on the 'unique within the same PC'. Fire up two instances of Fox; into the command window of the first paste this code:
>
>
public s, n
>s = _cliptext
>n = 0
>? m.s
>do while not (sys(2015) == m.s)
>   n = m.n + 1
>enddo
>? m.n
>
>Don't execute this yet. Into the command window of the second Fox paste this and execute:
>
>
local i
>for i = 1 to 1000000
>   = sys(2015)
>next i
>_cliptext = sys(2015)
>? _cliptext
>
>Then switch back to the first Fox pronto and execute the code you pasted earlier. If Nick is right then this will never terminate but I don't think you'll have to wait very long.


You forget that Windows multitasking is really time sliced. Therefore, the above mentioned two VFP instances/processes will never work literally at the same time

For example, from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/multitasking.asp


A multitasking operating system divides the available processor time among the processes or threads that need it. The system is designed for preemptive multitasking; it allocates a processor time slice to each thread it executes. The currently executing thread is suspended when its time slice elapses, allowing another thread to run. When the system switches from one thread to another, it saves the context of the preempted thread and restores the saved context of the next thread in the queue.

The length of the time slice depends on the operating system and the processor. Because each time slice is small (approximately 20 milliseconds), multiple threads appear to be executing at the same time.


>For names shared across processes - filenames etc. - you could use the classic technique of combining a locally unique id (SYS(2015)) with some info that uniquely identifies its generator - i.e. process id plus module handle of the Fox runtime. If the filename needs to be unique on the network then you could add the NetBIOS computer name or the DNS name. But in most such cases one can skip this effort and simply call SYS(2015) until an unoccupied filename is found, which is usually (99.9999...% of all cases) on the first try. Which approach is best really depends on the specific application.

On the network I would just use GUID rather than imitate it with SYS(2015) and other prefixes/suffixes.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform