Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

sky (1411)

  (email not shown publicly)

sky on IRC

Journal of sky (1411)

Wednesday May 09, 2001
06:06 AM


[ #154 ]
Was up late last night experimenting, and succeded in the following.

Making my $foo : ishared; work
It ties to a iThread::Share variable which stores the scalar and mutex protects it.

lock($foo) and unlock($foo)
Locks the mutex of the iThread::Share structure, replaces perls builtin lock and unlock. Unfournatly it does not automaticly unlock when the lock goes out of scope, it would be nice to do so, but it requires modifying the callers context and inserting the lock object there, however I am NOT going to do that yet.
The threadsafe version of localtime is around 100% slower than plain localtime(), so if it is a real problem I guess we have to fix it and use localtime_r, but that is not something I can do and this works for the time being.

This implments a threadsafe wrapper around localtime and installs it into CORE::GLOBAL. It is protected by a shared variable that it mutexes on. This worked threadsafly

All of these efforts are part of my effort to make iThreads work without modifying the core. I think that is essential to the ability to get them adopted, if in the future optimizations can be done by adding code to the core, perhaps that could be done.

On my todo now.

  • Fix so shared arrays and hashes work
  • Fix so you can't lock something twice
  • Make an attempt at working out a sane referencecounting of Shared Variables
  • Write a test script that tests more perl functions for threadsafeness

Cheers! Artur