Randi Botse | 2 Dec 2011 10:23
Picon

Co-thread for parallel processing

My program use co-threads, because creating and reinitialize thread is
expensive, it first create threads and reuse them. The main thread
will send each co-thread a event (through condition variable)
simultaneously to do task in parallel way. Each co-thread has variety
work-time, let say it can be (in miliseconds) 200ms, 130ms, 317ms,
90ms etc to get result to be consumed by main thread.

Here I did to wake-up all threads in the main thread:

.....
for (i = 0; i < nthread; i++)
    pthread_cond_broadcast(&cond);
wait_all_worker(); /* wait for all worker threads to finish */
get_all_worker_result(); /* get result from all worker thread */
...

And worker-thread routines:

...
for (;;) {
  pthread_mutex_lock();
  pthread_cond_wait();
  pthread_mutex_unlock();

  do_work();
  fill_result();
}
....

My dilema is:
(Continue reading)

Bogdan Cristea | 2 Dec 2011 10:28
Picon
Gravatar

Re: Co-thread for parallel processing

On Friday 02 December 2011 10:23:49 you wrote:
> My program use co-threads, because creating and reinitialize thread is
> expensive, it first create threads and reuse them. The main thread
> will send each co-thread a event (through condition variable)
> simultaneously to do task in parallel way. Each co-thread has variety
> work-time, let say it can be (in miliseconds) 200ms, 130ms, 317ms,
> 90ms etc to get result to be consumed by main thread.
> 
> Here I did to wake-up all threads in the main thread:
> 
> .....
> for (i = 0; i < nthread; i++)
>     pthread_cond_broadcast(&cond);
> wait_all_worker(); /* wait for all worker threads to finish */
> get_all_worker_result(); /* get result from all worker thread */
> ...
> 
> 
> And worker-thread routines:
> 
> ...
> for (;;) {
>   pthread_mutex_lock();
>   pthread_cond_wait();
>   pthread_mutex_unlock();
> 
>   do_work();
>   fill_result();
> }
> ....
(Continue reading)

Randi Botse | 2 Dec 2011 11:10
Picon

Re: Co-thread for parallel processing

> I would use  a semaphore...
Ok, let see what I can do with that.

2. Just forget that, that might be caused by my frustation... ;)

> 2. After calling pthread_cond_signal() or pthread_cond_broadcast()
> followed by sleep()/nanosleep(),
>     the condition variable looks like not signaled, (the co-thread
> routine doesn't run). What make this?

I don't understand, please provide a working example

> Bogdan
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Srinivasa T N | 2 Dec 2011 12:26
Picon

Re: Co-thread for parallel processing


> 1. What the proper way to the main thread to wait for all co-threads
> until finished?
> 2. After calling pthread_cond_signal() or pthread_cond_broadcast()
> followed by sleep()/nanosleep(),
>      the condition variable looks like not signaled, (the co-thread
> routine doesn't run). What make this?
I think you need a pthread_cond_broadcast () after do_work () in each 
thread.

Regards,
Seenu.

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Hendrik Visage | 3 Dec 2011 22:13
Picon

Re: Co-thread for parallel processing

On Fri, Dec 2, 2011 at 11:23 AM, Randi Botse <nightdecoder <at> gmail.com> wrote:
> 1. What the proper way to the main thread to wait for all co-threads
> until finished?

I'll do a semop() with sem_op=1 in each thread's start, and a
sem_op=-1 when each thread's finished.
Then in the main thread I'll wait with a sem_op = 0.

> 2. After calling pthread_cond_signal() or pthread_cond_broadcast()
> followed by sleep()/nanosleep(),
>    the condition variable looks like not signaled, (the co-thread
> routine doesn't run). What make this?

Please show the code snippet in the co-thread that is not working as
well as the mainthread's method you try to wake up the co-threads
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Krzysztof | 11 Dec 2011 09:17
Picon
Favicon

program icon

How to set the program icon to be showed e.g. on GUI desktop?

--

-- 
Regards
Krzysztof J.

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Javier Martinez Canillas | 11 Dec 2011 09:57
Picon
Gravatar

Re: program icon

On Sun, Dec 11, 2011 at 9:17 AM, Krzysztof <kj <at> limes.com.pl> wrote:
> How to set the program icon to be showed e.g. on GUI desktop?
>
> --
> Regards
> Krzysztof J.
>
>

Not sure if I understand your question, but if what you want is to
have an application launcher with an icon in your desktop. You have to
create an .desktop file an copy it to ~/Desktop/. For example
app.desktop could be:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/usr/local/myapp/bin/myapp
Name=MyApp
Icon=//usr/local/myapp/img.png

Hope it helps,

--

-- 
Javier Martínez Canillas
(+34) 682 39 81 69
Barcelona, Spain
(Continue reading)

Jesse Ruffin | 11 Dec 2011 11:19
Gravatar

Re: program icon


The standard for desktop entries, including associated icons:

http://standards.freedesktop.org/desktop-entry-spec/latest/

On 12/11/2011 03:57, Javier Martinez Canillas wrote:
> On Sun, Dec 11, 2011 at 9:17 AM, Krzysztof <kj <at> limes.com.pl>
> wrote:
>> How to set the program icon to be showed e.g. on GUI desktop?
>> 
>> -- Regards Krzysztof J.
>> 
>> 
> 
> Not sure if I understand your question, but if what you want is to 
> have an application launcher with an icon in your desktop. You have
> to create an .desktop file an copy it to ~/Desktop/. For example 
> app.desktop could be:
> 
> #!/usr/bin/env xdg-open
> 
> [Desktop Entry] Version=1.0 Type=Application Terminal=false 
> Exec=/usr/local/myapp/bin/myapp Name=MyApp 
> Icon=//usr/local/myapp/img.png
> 
> Hope it helps,
> 
Krzysztof | 11 Dec 2011 19:30
Picon
Favicon

Re: program icon

On 12/11/2011 09:57 AM, Javier Martinez Canillas wrote:
> On Sun, Dec 11, 2011 at 9:17 AM, Krzysztof<kj <at> limes.com.pl>  wrote:
>> How to set the program icon to be showed e.g. on GUI desktop?
>>
>> --
>> Regards
>> Krzysztof J.
>>
>>
> Not sure if I understand your question,
Is it possible to set it at compilation/linking stage?

--

-- 
Regards
Krzysztof J.

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Aniruddha Bhattacharyya | 11 Dec 2011 19:33
Picon

Re: program icon

So you want it like windows linker?
(embedding as a resource icon)

On Mon, Dec 12, 2011 at 12:00 AM, Krzysztof <kj <at> limes.com.pl> wrote:
>
> On 12/11/2011 09:57 AM, Javier Martinez Canillas wrote:
>>
>> On Sun, Dec 11, 2011 at 9:17 AM, Krzysztof<kj <at> limes.com.pl>  wrote:
>>>
>>> How to set the program icon to be showed e.g. on GUI desktop?
>>>
>>> --
>>> Regards
>>> Krzysztof J.
>>>
>>>
>> Not sure if I understand your question,
>
> Is it possible to set it at compilation/linking stage?
>
> --
> Regards
> Krzysztof J.
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
(Continue reading)


Gmane