in reply to a question on sharing data structures across threads
obviously this cannot work, since we're having a lock on the variable in the very moment when we try to delete it, and consequently the result is: panic: MUTEX_LOCK (22) ( shared.xs:90), and as i recall to have read somewhere that lock() isn't atomic, it would be no threadsafe solution if we put the delete() outside of the lock block. seems to me that locking the whole hash/ array is the only realistic possibility for the moment. but maybe some fine day in future one of the perl developers happens to stumble on this thread... ^^foreach (keys %planets) { lock %{$planets{$_}}; [...] if ($planets{$_}->{'atime'} < $time - $some_limit) { delete $planets{$_}; # remove the item from cache } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: a question on sharing data structures across threads
by BrowserUk (Patriarch) on Oct 09, 2007 at 12:38 UTC |