For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > February 2006 > Thread safe









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Thread safe
Sreenath G K

2006-02-02, 4:00 am

Hi all,

I am working in Visualworks 7.3.1.Is it possible to make a global variable
thread safe like "synchronise" in java.
Thanks in advance.

Sreenath


David Buck

2006-02-02, 7:59 am

Sreenath G K wrote:
> Hi all,
>
> I am working in Visualworks 7.3.1.Is it possible to make a global variable
> thread safe like "synchronise" in java.
> Thanks in advance.
>
> Sreenath


You would a class instance variable containing a semaphore and use the
critical: method to protect your code.

Eg.

instance method of MyClass:

writeToFile: someData
self class mySemaphore critical: [
someData writeToFile]


class method of MyClass

mySemaphore
^semaphore

initialize
semaphore := Semaphore forMutualExclusion

David Buck
Simberon Inc.
www.simberon.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com