[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug: defining things in different threads
From: |
Linas Vepstas |
Subject: |
Re: bug: defining things in different threads |
Date: |
Wed, 12 Nov 2008 11:27:33 -0600 |
2008/11/12 Ludovic Courtès <address@hidden>:
> Hi Linas,
>
> "Linas Vepstas" <address@hidden> writes:
>
>> void * scm_one (void *p)
>> {
>> prtdbg("thread one");
>> scm_c_eval_string ("(define x \"asddf\")\n");
>> }
>>
>> void * scm_two (void *p)
>> {
>> prtdbg("thread two");
>> scm_c_eval_string ("(display x)\n");
>> }
>
> AFAICS, there's not proper synchronization between these two threads
> (e.g., a barrier), so it could be that thread 1 gets to define `x' after
> thread 2 attempts to access it. Sure, there's a "sleep (1);", but a
> barrier would make sure we're not seeing such a case.
>
> Can you add proper synchronization and see if the problem is still here?
Ludo,
I am sorry I mailed out such a lame example, but surely
you must be joking when you make such a request! The
answer is, of course, obvious; the sleep is a defacto
thread yield. Program correctness is easily verified
simply by looking at the tty while the program is running.
You may replace the first sleep by pthread_join(t1, NULL);
and the second one by pthread_join(t2, NULL); to get
your desired posixly-correct synchronization.
Yes, of course, the problem remains.
--linas