Thursday, May 28, 2009

comp.programming.threads - 8 new messages in 5 topics - digest

comp.programming.threads
http://groups.google.com/group/comp.programming.threads?hl=en

comp.programming.threads@googlegroups.com

Today's topics:

* Pthread programming issue: PTHREAD_STACK_MIN undeclared - 1 messages, 1
author
http://groups.google.com/group/comp.programming.threads/t/7d70ec464dba47f8?hl=en
* using a no reentrant library in a multithreaded application - 1 messages, 1
author
http://groups.google.com/group/comp.programming.threads/t/66509bc9ad66ec6c?hl=en
* pthread_create returns error code 11 - 4 messages, 2 authors
http://groups.google.com/group/comp.programming.threads/t/86e0fbae16cc43a7?hl=en
* Another look at synchronisation implementations - 1 messages, 1 author
http://groups.google.com/group/comp.programming.threads/t/94f39a94cfc85076?hl=en
* Using a thread to complete object initialization - 1 messages, 1 author
http://groups.google.com/group/comp.programming.threads/t/64cb03b37b5d9fea?hl=en

==============================================================================
TOPIC: Pthread programming issue: PTHREAD_STACK_MIN undeclared
http://groups.google.com/group/comp.programming.threads/t/7d70ec464dba47f8?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, May 26 2009 12:43 pm
From: climber.cui@gmail.com

> #include <limits.h>
>
> DS

Thanks David. It works!!

tony

==============================================================================
TOPIC: using a no reentrant library in a multithreaded application
http://groups.google.com/group/comp.programming.threads/t/66509bc9ad66ec6c?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, May 27 2009 10:05 am
From: andrew@cucumber.demon.co.uk (Andrew Gabriel)


In article <3OidnfW909p4Z5fXnZ2dnUVZ_qOdnZ2d@posted.sasktel>,
Chris Friesen <cbf123@mail.usask.ca> writes:
> Francis Moreau wrote:
>
>> I have to use a library which doesn't support multithreads.
>>
>> Is it possible/enough to use this lib in a multithread context by
>> using a global mutex that allows only one thread to call the lib at a
>> time ?
>
> It's not safe in general, but depending on what the library actually
> does it could be safe in your particular scenario.
>
> One problem that may arise is if the library uses something like
> gethostbyname(), which points to a static data structure. None of your
> threads should be using it directly, but if you had another library
> (protected by a different mutex) a second thread could end up calling
> gethostbyname() and overwriting the results of the call in the first
> thread. In this case, protecting both libraries with the same mutex
> would solve the problem.
>
> Another possible source of problems is if the library does anything
> related to signal handling. It could conceivably expect signals to
> arrive in that particular thread, and this could potentially cause problems.

Solaris does support this, providing the non-thread-safe library(s)
are only called from the main/initial thread. Since they can only be
called from one thread, no global mutex is required.

If you call them from other threads, the sort of problem they'll
have is that they will be seeing/using the wrong thread's errno
variable.

Other OS's won't necessarily handle things the same way though.

--
Andrew Gabriel
[email address is not usable -- followup in the newsgroup]

==============================================================================
TOPIC: pthread_create returns error code 11
http://groups.google.com/group/comp.programming.threads/t/86e0fbae16cc43a7?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, May 27 2009 10:32 am
From: Harshith


I read up that this could be due to exceeding the THREAD_MAX limit for
the process. But i want to use only about 24 threads at a given time,
and i destroy the threads (or atleast i thought so) can someone tell
me what i am doing wrong here it would be of great help! thanks!

for (i=0; i<no_pairs; ){
for (j=0; j<MAX_THREADS && i<no_pairs; j++,i++){
data[j].a = seeds[i/no_seeds];
data[j].b = seeds[i%no_seeds];
data[j].N = N;
data[j].L = nones+nzeros;
data[j].p1 = get_string (seeds[i/no_seeds], nzeros
+nones-1);
data[j].p2 = get_string (seeds[i%no_seeds], nzeros
+nones-1);
data[j].results = pairs[i];
rc = pthread_create (&threads[j], &attr, run_actree,
(void*)&data[j]);
if (rc) {
printf ("ERROR; return code from pthread_create() is %d
\n", rc);
exit (-1);
}
}
for (k=0; k<j; k++){
rc = pthread_join (threads[k], &status);
if (rc) {
printf("ERROR; return code from pthread_join() is %d
\n", rc);
exit(-1);
}
}
}

pthread_attr_destroy (&attr);

Above is the main loop i create threads in, MAX_THREADS = 24

the number of pairs is about 300 million, the above code worked
correctly (or atleast the results seemed correct and there were no
errors) for 2 million pairs.


== 2 of 4 ==
Date: Wed, May 27 2009 11:02 am
From: David Schwartz


On May 27, 10:32 am, Harshith <harshi....@gmail.com> wrote:
> I read up that this could be due to exceeding the THREAD_MAX limit for
> the process. But i want to use only about 24 threads at a given time,
> and i destroy the threads (or atleast i thought so) can someone tell
> me what i am doing wrong here it would be of great help! thanks!

Whether or not this should work, why would someone want to do
something so horribly awful?

DS


== 3 of 4 ==
Date: Wed, May 27 2009 2:02 pm
From: Harshith


LOL because its my work :)
anyways i found out the reason and it turns out it has nothing to do
with this code - its because 300 million just makes me run out of 8 gb
or ram and 16 gb of swap :)

anyways barcelona won the champiions league hurray!!
and sorry for wasting your time with this post :)


== 4 of 4 ==
Date: Wed, May 27 2009 2:44 pm
From: David Schwartz


On May 27, 2:02 pm, Harshith <harshi....@gmail.com> wrote:

> LOL because its my work :)

I don't see why that requires you to create and destroy threads rather
than reusing them.

DS

==============================================================================
TOPIC: Another look at synchronisation implementations
http://groups.google.com/group/comp.programming.threads/t/94f39a94cfc85076?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, May 27 2009 10:51 am
From: Markus Elfring


> If they fail the CV_TEST, they must be fixed.

Do you recommend any concrete fixes for the source code of the mentioned
software examples?

Regards,
Markus

==============================================================================
TOPIC: Using a thread to complete object initialization
http://groups.google.com/group/comp.programming.threads/t/64cb03b37b5d9fea?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, May 27 2009 11:09 am
From: "vl106"


I have the following problem: a function shall return a complex object. The
caller
shall receive the object immediately (e.g. without blocking). The real
initialization
is done by a worker thread (as being time-consuming). I came up with the
following
solution. Any better ideas?

For simplicity the thread here is just a plain function.

#include <iostream>

class C {
public:
C(int* value) : value_(value) {}
void f();
private:
int* value_;
};

void C::f() {
// threadsafe_begin
int val = *value_;
// threadsafe_end
if(val) {
// do something useful...
std::cout << val;
}
}

void thread(int* value) {
// threadsafe_begin
*value = 123;
// threadsafe_end
}

int main() {
int* val = new int(0);
C aC(val);
thread(val);
aC.f();
return 0;
}


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.programming.threads"
group.

To post to this group, visit http://groups.google.com/group/comp.programming.threads?hl=en

To unsubscribe from this group, send email to comp.programming.threads+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.programming.threads/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: