Nonblocking for nacl io

98 views
Skip to first unread message

Andrew

unread,
Feb 8, 2015, 3:26:21 AM2/8/15
to native-cli...@googlegroups.com
Hi!

I have a question regarding nacl_io.

What operations are actually supported on the main thread?

Can I use regular BSD sockets with nonblocking flag set without using an additional thread? Looks like getaddrinfo doesn't work, but what about select, sendto, recv, ...?

Can I use fopen, fread, fwrite, fclose to read/write small file on persistent file system on the main thread? It seems like memory fs works just fine.

I clearly understand that the main thread shouldn't be blocked, but I would like to avoid using threads as much as possible.

Victor Khimenko

unread,
Feb 8, 2015, 5:29:33 AM2/8/15
to Native Client Discuss
On Sun, Feb 8, 2015 at 11:26 AM, Andrew <andrew.s...@gmail.com> wrote:
Hi!

I have a question regarding nacl_io.

What operations are actually supported on the main thread?

Practically nothing. You could change nacl_io configuration and do some things which could work without interaction with outside world (things like in-memory file system) and that's it.
 
Can I use regular BSD sockets with nonblocking flag set without using an additional thread? Looks like getaddrinfo doesn't work, but what about select, sendto, recv, ...?

Some of these may work in some circumstances by accident, but it's not something you should do. Usually they must interact with the outside world and for that to happen you main thread should be in the message loop.
 
Can I use fopen, fread, fwrite, fclose to read/write small file on persistent file system on the main thread? It seems like memory fs works just fine.

Memory fs works just fine because it does not need to talk to browser.
 
I clearly understand that the main thread shouldn't be blocked, but I would like to avoid using threads as much as possible.

It'll not work. Most POSIX APIs (emulated by nacl_io) assume that they could return some information back when called. This could never happen with PPAPI: all the information is supplied back in the callbacks, it's not returned to function directly. Thus only APIs implemented with some kind of caching could work: first they fail, then your program reliquishes the main thread and callback is called, then, on the next "pass" correct [cached] information is returned. If you REALLY don't want to use threads then you could use PPAPI directly, I think, but this is PITA: you'll need to reliquish control after each call to any function and continue to execute business logic when callback is called - this is not how typical C/C++ code does things.

Andrew

unread,
Feb 8, 2015, 8:29:33 AM2/8/15
to native-cli...@googlegroups.com

Thanks a lot for your reply! I will move to PPAPI for sockets. Not sure what do with persistent file system yet.

Another small question: is it possible to use OpenGL from non main thread? Some years ago it wasn't possible at all. If yes, will it work as fast as on the main thread?

Victor Khimenko

unread,
Feb 8, 2015, 9:45:41 AM2/8/15
to Native Client Discuss
On Sun, Feb 8, 2015 at 4:29 PM, Andrew <andrew.s...@gmail.com> wrote:

Thanks a lot for your reply! I will move to PPAPI for sockets. Not sure what do with persistent file system yet.

Another small question: is it possible to use OpenGL from non main thread? Some years ago it wasn't possible at all. If yes, will it work as fast as on the main thread?

All system calls could be called from non-main thread. This deficiency was fixed when switch to new proxy was introduced:
 



On Sun, Feb 8, 2015 at 11:26 AM, Andrew <andrew.s...@gmail.com> wrote:
Hi!

I have a question regarding nacl_io.

What operations are actually supported on the main thread?

Practically nothing. You could change nacl_io configuration and do some things which could work without interaction with outside world (things like in-memory file system) and that's it.
 
Can I use regular BSD sockets with nonblocking flag set without using an additional thread? Looks like getaddrinfo doesn't work, but what about select, sendto, recv, ...?

Some of these may work in some circumstances by accident, but it's not something you should do. Usually they must interact with the outside world and for that to happen you main thread should be in the message loop.
 
Can I use fopen, fread, fwrite, fclose to read/write small file on persistent file system on the main thread? It seems like memory fs works just fine.

Memory fs works just fine because it does not need to talk to browser.
 
I clearly understand that the main thread shouldn't be blocked, but I would like to avoid using threads as much as possible.

It'll not work. Most POSIX APIs (emulated by nacl_io) assume that they could return some information back when called. This could never happen with PPAPI: all the information is supplied back in the callbacks, it's not returned to function directly. Thus only APIs implemented with some kind of caching could work: first they fail, then your program reliquishes the main thread and callback is called, then, on the next "pass" correct [cached] information is returned. If you REALLY don't want to use threads then you could use PPAPI directly, I think, but this is PITA: you'll need to reliquish control after each call to any function and continue to execute business logic when callback is called - this is not how typical C/C++ code does things.

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.

Andrew

unread,
Feb 26, 2015, 4:44:25 PM2/26/15
to native-cli...@googlegroups.com
Maybe a stupid question: why does the main thread exist? It has only restrictions, and seems doesn't have any features now.

Why not to make all threads as non-main?

Why pepper API doesn't have function like PumpMessages for the main thread?

I have to write a lot of code just to put string in localStorage because synchronous javascript calls are not allowed.
Reply all
Reply to author
Forward
0 new messages