chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] srfi-18 and reading/writing variables, how to simula


From: Jörg F . Wittenberger
Subject: Re: [Chicken-users] srfi-18 and reading/writing variables, how to simulate a collision?
Date: 30 Nov 2016 14:35:27 +0100

Hi Matt,

I'm not sure I can give a definite answer, but...

On Nov 30 2016, Matt Welland wrote:

My question: Do green threads naturally do atomic reads/writes to variables
such that mutexes are pragmatically not needed in most situations in
Chicken?

Yep.  That is: it depends.

Single fields are thread-safe wrt. "green threads". Protecting testit-x-set! with a mutex should not have any effect.

If you need several assignements (say testit-x-set! and testit-y-set!) within an atomic unit, you need either a mutex protection, or you may compile with (declare (disable-interrupts)) (or cmd line -disable-interrupts).

I have seen corrupted values which I assumed were due to reading/writing to
variables from multiple threads without mutex protection. However when I
tried to simulate this (code pasted below) I haven't been able to create
any collisions.

Note that where file handles and ports are being opened/closed with subprocesses etc then mutexes are absolutely needed. I ran into this with trying to use nanomsg in threads where subprocesses were being launched.

Dunno: maybe "nanomsg" is the culprit.

I've been trying to use nanomsg too. But found that the library does not work reliable in the presence of fork(2).

You need to do all fork()s before you initialize nanomsg.

/Jörg

Without mutexes it crashed very quickly. It is possible that the corrupted values I've seen in the past were actually due to open/closing of file handles, ports and or processes along with cross threaded variable accesses.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]